swift中的静态字符串常量评估为空字符串“”

时间:2015-10-01 13:21:48

标签: swift

为什么我的字符串常量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]
       {
       }
    }

0 个答案:

没有答案