Thursday, May 2, 2013

NSKeyedArchiver archivedDataWithRootObject example ios


archivedDataWithRootObject:

Returns an NSData object containing the encoded form of the object graph whose root object is given.
+ (NSData *)archivedDataWithRootObject:(id)rootObject
Parameters
rootObject
The root of the object graph to archive.
Return Value of [NSKeyedArchiver archivedDataWithRootObject]
An NSData object containing the encoded form of the object graph whose root object isrootObject. The format of the archive is NSPropertyListBinaryFormat_v1_0.
Example of [NSKeyedArchiver archivedDataWithRootObject]
NSArray* array= ... ;
NSData* data=[NSKeyedArchiver archivedDataWithRootObject:array];
Example of [NSKeyedArchiver archivedDataWithRootObject]
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:notes];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:@"notes"];

NSData *notesData = [[NSUserDefaults standardUserDefaults] objectForKey:@"notes"];
NSArray *notes = [NSKeyedUnarchiver unarchiveObjectWithData:notesData];
Example of [NSKeyedArchiver archivedDataWithRootObject]
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:results];
[prefs setObject:data forKey:@"lastResults"];