Archiving and archiving of data

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.