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