About archiving for iOS

Source: Internet
Author: User
Tags xml attribute

Archiving, in other languages called "serialization", is to save the object to the hard disk, the solution, in other languages called "deserialization" is to restore the hard disk files to objects. In fact, archiving is the process of data storage, there are five ways to store data in iOS:

    1. XML attribute list (plist archive)

    2. Nsuserdefaults (preference setting)

    3. Nskeyedarchiver Archive (encrypted form)

    4. SQLite3 (embedded database)

    5. Core Data (embedded database for object-oriented approach)

First, let's take a look at the XML attribute list, the XML attribute list is archived by storing objects in a plist file, which is relatively simple to do, in fact, equivalent to XML serialization. But at the same time it also has shortcomings: first, this method is clear-text preservation, and the other is that the object of operation is limited, only Nsarray, Nsmutablearray, Nsdictionary, Nsmutabledictionary support (as long as the corresponding WriteToFile method is called when archiving, the solution calls Arraywithcontentsoffile or Dictionarywithcontentsoffile, Note that, like NSString, NSNumber, NSData even if this method is stored, it is not in XML format.

Second, if you want to archive for more objects or to be able to encrypt when you need to archive, you need to use Nskeyedarchiver for archiving and file, the scope of this method of archiving is more extensive and archived content is ciphertext storage. From the archive scope Nskeyedarchiver is suitable for all OBJC objects, but we need to implement the Nscoding protocol for custom objects, and from the archiving approach Nskeyedarchiver is divided into simple archives and complex object archives, A simple archive is a single object that can be directly used as a root object (without setting a key), a complex object is targeted at multiple objects, and different objects need to be set to different keys when stored.

If ported to iOS apps, change Nsarchiver and Nsunarchiver to Nskeyedarchiver and Nskeyedunarchiver. While the foundation section iOS and OS X are designed to be as generic as possible, there are subtle differences.

About archiving for iOS

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.