Skip to content

Instantly share code, notes, and snippets.

@onmyway133
Last active August 29, 2015 13:58
Show Gist options
  • Save onmyway133/9978199 to your computer and use it in GitHub Desktop.
Save onmyway133/9978199 to your computer and use it in GitHub Desktop.
NSKeyedArchiver
Get document directory
NSString *documentDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *filePath = [documentDir stringByAppendingPathComponent:@"file.bin"];
Save
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:object];
[NSKeyedArchiver archiveRootObject:data toFile:filePath];
Load
NSData *data = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
id object = [NSKeyedUnarchiver unarchiveObjectWithData:data];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment