如何在swift 3中声明:
// objective c
static id currentInstance;
然后执行此操作
// objective c
+ (id)getCurrentViewController {
return currentInstance;
}
答案 0 :(得分:2)
static let currenInstance: Any = /*YourClass*/()
static func getCurentViewController() -> Any {
return /*YourClass*/.currentInstance
}
答案 1 :(得分:1)
这样的事情:
class CurrentInstanceHolder {
private static var currentInstance:Any!
static func getCurrentInstance() -> Any {
return currentInstance
}
static func setCurrentInstance(_ instance:Any) {
currentInstance = instance;
}
}
CurrentInstanceHolder.setCurrentInstance("aa")
print(CurrentInstanceHolder.getCurrentInstance())
您可以使用Any
或您的特定类型,而不是AnyObject
。您也可以将所有静态信息放入具体类型中。