为什么我的字符串常量kAppCacheKey在我第一次访问它时会计算为空字符串?它在后续调用时显示为字符串“myAccount”。
我是否以正确的方式声明静态常量?
let kAppCacheKey = "myAccount"
class LoggedUser {
class var sharedInstance: LoggedUser {
struct Static {
static let instance = LoggedUser.loadFromCache()
}
return Static.instance
}
override private init() {
super.init()
}
private class func loadFromCache() -> LoggedUser {
//kAppCacheKey is evaluated as an empty string here for some reason
if let data = Locksmith.loadDataForUserAccount(kAppCacheKey) as? [String:String]
{
}
}