Archive Summary of iOS development

Source: Internet
Author: User
Tags xml attribute

Archive only for Foundation objects:

Using an XML attribute list archive, the result is an XML file, and the attribute list archive is for the foundation object only, and if there are objects of certain custom classes in the array or dictionary collection, this method cannot be archived.

How to use the archive:

Use the method that comes with the Foundation class:-(BOOL) WriteToFile: (NSString *) path atomically: (bool) useauxiliaryfile;

The corresponding parsing method:-(ID) Initwithcontentoffile: (NSString *) FilePath;

The two methods are relative. With a self-documenting method, you must use your own method to read the file. If you read it in another way, an exception occurs.

Ways to archive Custom classes:

Filed with Nsarchiver and Nskeyedarchiver.

There is no nsarchiver in the iOS SDK (Nsarchiver is a method in the Mac OS SDK). Only Nskeyedarchiver and nskeyedunarchiver can be used for archiving and parsing operations.

Nsarray *[email protected][@ "1" @ "2" @ "3"];

[Nskeyedarchiver archiverootobject:array tofile:@ "arrtemp"]; Archive operations

Nsarray *arr=[nskeyedunarchiver unarchiveobjectwithfile:@ "arrtemp"]; Read File operation

Custom classes should follow the <NSCoding> protocol approach when archiving with Nskeyedarchiver for key-value pairs.

How to encode the archive

-(void) Encodewithcoder: (Nscoder *) Acoder

{

[Acoder encodeobject:bookname forkey:@ "name"];

}

How to read a file for decoding

-(ID) Initwithcoder: (Nscoder *) Adecoder

{

Self.bookname = [Adecoder decodeobjectforkey:@ "name"];

return self;

}

Archive Summary of iOS development

Related Article

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.