Storing a variable when the app is first installed

后端 未结 2 1979
天涯浪人
天涯浪人 2021-01-17 01:34

Attempting to store the variable DateInstalled when the app is first installed, but each time the app loads this variable is overridden by the new date.

<
2条回答
  •  不思量自难忘°
    2021-01-17 02:08

    Hey @Curtis Cowan try with this

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    
                let firstLaunch = NSUserDefaults.standardUserDefaults().boolForKey("FirstLaunchTime")
                if firstLaunch  {
                   println("Not First launch")
                }
                else {
                    println("First launch")
                    NSUserDefaults.standardUserDefaults().setObject(NSDate(), forKey:"FirstLaunchTime")
                     }
    
                return true
          }
    

提交回复
热议问题