2

Why does my string constant kAppCacheKey evaluate to an empty string the first time I access it? It shows up as the string "myAccount" on subsequent calls to it.

Am I declaring static constants in the right way?

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]
       {
       }
    }
MonkeyBonkey
  • 46,433
  • 78
  • 254
  • 460
  • 2
    not related to the problem, but the preferred way of creating singletons in Swift now is described here: http://stackoverflow.com/a/24147830/2592349 – Dániel Nagy Oct 01 '15 at 13:35

0 Answers0