Created
October 21, 2015 19:43
-
-
Save casspangell/a87614795f54f8dfffa1 to your computer and use it in GitHub Desktop.
Saving Data to NSUserDefaults
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Given `notes` contains an array of Note objects | |
//Archive | |
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:notes]; | |
[[NSUserDefaults standardUserDefaults] setObject:data forKey:@"notes"]; | |
//Unarchive | |
NSData *notesData = [[NSUserDefaults standardUserDefaults] objectForKey:@"notes"]; | |
NSArray *notes = [NSKeyedUnarchiver unarchiveObjectWithData:notesData]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment