Objective-C magic path [19-Archive], objective-c19-Archive
Master haomeng is devoted to his contribution and respects the author's Labor achievements. Do not repost them.
If the article is helpful to you, you are welcome to donate to the author, support haomeng master, the amount of donation is free, focusing on your mind ^_^
I want to donate: Click to donate
Cocos2d-X source code download: point I send
In Objective-C, archiving is a process,
You can save one or more objects in a certain format to restore them later.
Similar to Java serialization and deserialization.
Applications on Mac OS X use the XML Attribute list (or plists)
Store data such as default parameter selection, application settings, and configuration information.
Use the PropertyList Editor program to create an attribute list.
You can use the NSPropertyListSerialization class to write or read attribute lists in files and port them between different platforms.
Archive methods generally include:
1) Use the XML Attribute list for archiving. (If possible, try to use the XML Attribute list in the Program)
2) use NSKeyedArchiver for archiving.
3) Use NSData to create a custom file.
To archive objects that are not currently listed, you must inform the system of How to archive (or encode) Your objects and how to archive (or decode) them.
According to the <NSCoding> protocol, add encodeWithCoder: method and initWithCoder: Method to the class definition.
Each time the archive program wants to encode an object based on the specified class, it will call the encodeWithCoder: method,
This method tells the archive program how to archive.
Similarly, every time an object is decoded from a specified class, the initWIthCoder: method is called.
Generally, the encoding method should specify how to archive each instance variable in the object to be saved.
It is easy to recover data from an archive file: the work is only opposite to that of an archive file.
First, you need to allocate a data space as before.
Second, read the data in the archive file into the data space.
Then, you need to create an NSKeydUnarchiver object and notify it to decode data from the specified space.
You must call the decoding method to extract and decode the archived object. After that, you can send a finishDecoding message to the NSKeyedUnarchiver object.
Use the archive program to copy objects:
You can use the archive function of Foundation to create deep copy of objects.