Archiving and archiving of data
Archive
BOOL success = [Nskeyedarchiver archiverrootobject: Archived object tofile: File path];
Solution file
ID content = [nskeyedunarchiver unarchiveobjectwithfile: File path];
Second Solution archive (multi-object)
Archive
NSString *homepath = Nshomepath ();
NSString *filepath = [HomePath stringbyappendingpathcomponent: Archive file name];
Nsmutabledata *data = [Nsmutabledata data];
Nskeyedarchiver *archive = [[Nskeyedarchiver alloc]initforwritingmutabledata:data];
[Archive encodeint:100 forkey:@ "age"];
[Archive Encodeobject: Object name Forkey: @ "name"];
[Archive finishencode];
[Archive release];
BOOL success = [data Writetofile:filepath atomically:yes];
Solution file
NSString *homepath = Nshomepath ();
NSString *filepath = [HomePath stringbyappendingpathcomponent: Archive file name];
NSData *data = [NSData Datawithcontentsoffile:filepath];
Nskeyedunarchiver *unarchive = [[Nskeyedunarchiver alloc]initforreadingwithdata:data];
int num = [unarchive decodeintforkey:@ "age"];
ID obj = [unarchive decodeobjectforkey:@ "name"];
[Unarchive release];
When customizing the archive, follow the Nsecoding protocol.
The way to implement it when archiving
-(void) Encodewithcoder: (Nscoder *) acoder{}
When you do the file,
-(void) Initwithcoder: (Nscoder *) acoder{
self = [super init];
if (self! = nil) {
}
return self;
}//note the ownership of the property of a Point object
Archiving and archiving of data