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.
I am new to Xcode
so the answer is probably obvious. I found this code below to store the variable in the user defaults but every time it seems to skip to the else statement.
var DateInstalled: NSDate {
get {
if let returnValue = NSUserDefaults.standardUserDefaults().objectForKey("DateInstalled") as? NSDate {
return returnValue
} else {
NSLog("Saving new Date")
return NSDate() // Default value
}
}
set {
NSUserDefaults.standardUserDefaults().setObject(newValue, forKey: "DateInstalled")
NSUserDefaults.standardUserDefaults().synchronize()
}
}
first make your date optional:
and inside your viewDidLoad method add a conditional to only save its value if it stills nil:
Xcode 8 • Swift 3
Hey @Curtis Cowan try with this