AppDelegate.swift
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var userId:Int = 0 // <==== この変数を他のクラスからアクセスする
func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
// Override point for customization after application launch.
ViewController.swift (他のクラス)
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
// AppDelegateクラスのメンバー変数を参照する
var app:AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
println(app.userId)
}
動作環境
Xcode6beta3
0 件のコメント:
コメントを投稿