我的问题是我有常量类,它几乎在应用程序中的每个类中使用,所以我通过它在AppDelegate中创建了它的对象n想要访问它们。我不想创建对象常量,每次在哪里,哪些是最好的方法,请咨询。如何获取AppDelegate的参考
class AppDelegate: UIResponder, UIApplicationDelegate {
public var constants = Constants()
//created object once in app delegate
}
class Utility
{
let delegate = UIApplication.shared.delegate as! AppDelegate //getting null here
let constants = delegate. constants
}`
'UIApplicationDelegate'已经是一个独特的实例。千万不要创建它的副本。只需使用其参考。 –
[我如何获得对Swift中应用程序委托的引用?](http://stackoverflow.com/questions/24046164/how-do-i-get-a-reference-to-the-app-快速上传) – Vinodh
在添加重复问题之前进行搜索 – Vinodh