Wednesday, October 21, 2015

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];
view raw saving.m hosted with ❤ by GitHub

No comments:

Post a Comment

Blog Archive