Skip to content

Instantly share code, notes, and snippets.

@casspangell
Created October 21, 2015 19:43
Show Gist options
  • Save casspangell/a87614795f54f8dfffa1 to your computer and use it in GitHub Desktop.
Save casspangell/a87614795f54f8dfffa1 to your computer and use it in GitHub Desktop.
Saving Data to NSUserDefaults
// 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