I\'ve implemented an save on applicationWillTerminate
and load on applicationWillFinishLoading
.
There is a complete object tree, all implement the
FWIW I have also come across this problem and here is what I've found.
The bytes reported 0x62, 0x70, 0x6c, etc., are part of the magic string "bplist" at the start of a binary property list, which NSKeyedArchiver uses by default.
A binary property list stores metadata in a trailer (i.e. at the end of the data). So if it gets truncated, the entire plist becomes unreadable.
If you want to check whether that's what has happened to you, you can use NSPropertyListReader_binary1 from Cocotron (http://code.google.com/p/cocotron/source/browse/Foundation/NSPropertyList/) to see how the file format works.
Hope this helps someone!
For the bool and int, there are two methods: encodeBool:forKey:
and encodeInt:forKey:
(taken from the NSKeyedArchiver reference).
For the NSMutableData, you should archive them with encodeObjectForKey:
and unarchive them with decodeObjectForKey:
.
You can refer to this useful guide for more cases.
It seems that store more than around 230000 bytes via an NSMutableArray will cause the NSKeyedArchiver to create a broken plist file.
220000 works, 250000 didn't. Did search for the exact amount that is allowed.