如何使所有 Swift 个文件都可以访问变量?
How to make a variable accessible by all Swift files?
假设我要在应用委托中分配一个变量。我如何在不使用 segues 的情况下在所有其他视图 controllers/swift 文件中访问此变量?
UIApplication.sharedApplication().delegate
允许访问单例应用程序对象,因此:
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let x = appDelegate.myVariable
假设我要在应用委托中分配一个变量。我如何在不使用 segues 的情况下在所有其他视图 controllers/swift 文件中访问此变量?
UIApplication.sharedApplication().delegate
允许访问单例应用程序对象,因此:
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let x = appDelegate.myVariable