Last active
August 29, 2015 13:58
-
-
Save onmyway133/9978199 to your computer and use it in GitHub Desktop.
NSKeyedArchiver
This file contains hidden or 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
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