Archiving / Unarchiving results in initForReadingWithData incomprehensible archive

后端 未结 3 1574
無奈伤痛
無奈伤痛 2021-01-03 08:08

I\'ve implemented an save on applicationWillTerminate and load on applicationWillFinishLoading. There is a complete object tree, all implement the

相关标签:
3条回答
  • 2021-01-03 08:21

    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!

    0 讨论(0)
  • 2021-01-03 08:21

    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.

    0 讨论(0)
  • 2021-01-03 08:42

    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.

    0 讨论(0)
提交回复
热议问题