An issue about OC object Type data archiving

Source: Internet
Author: User

These two days to do a QQ landing system

When registering, the user enters various information (Name,age,password,gender. Avatar ...) stored in a user object, and then wants to put this object in a. txt file every time you register.

This is used in the following way:

Convert user to NSData (object archive), then append data to the end of file with Nsfilehandle, then read

But every time the first time to write to the file and read no problem, the second write is no problem, but again to read the time is always an error, probably is the file format is a problem.

Later I wondered why the system-type data like Nsdictionary can be written to read without problems, and the type of object that you create cannot always be appended to the end

The final conclusion is probably: the basic data type append is possible, but the object type, appended at the end of the file, then read the time will not be able to identify the object inside (now also can not remember the specific reason for it.) Next time remember to write again

Finally, the way to solve this problem is to:

Convert the object into NSData, put the NSData data in the dictionary, and then write the dictionary to the file, read it, read the NSData, extract the archive, and finally get to the object

That's about as much.

An issue about OC object Type data archiving

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.