When the app is loaded, I want to know whether I have already saved the data to disk. If it is saved, I just load from disk, if not, I save.
for example, I want to save an array(person) using NSUserDefaults.standardUserDefaults()
Save Method:
let defaults = NSUserDefaults.standardUserDefaults()
if let savedPeople = defaults.objectForKey("people") as? NSData
people = NSKeyedUnarchiver.unarchiveObjectWithData(savedPeople) as! [Person]
But how can I know if I have saved the data or not in viewDidLoad()
? I don't want to save every time I open the app, and it will also overwrite the data I modified before.