I implemented persistence on applicationWillTerminate and loaded on applicationWillFinishLoading . There is a complete tree of objects, all implement the NSCoding protocol, and I check the types that I entered.
One of the classes also stores NSMutableData in NSKeyedArchive , which, I suspect, can sometimes be interrupted. Oddly enough, sometimes it works, and sometimes not. I suspect some content in NSMutableData will violate archiving.
I use encodeObject for all objects except bools and int, where I use the correct appropriate method ( encodeBool:forKey: and encodeInt:forKey:
To be more clear: the code really works, sometimes it is able to rebuild a fairly complete graph of objects, but not all the time.
The error message I get is:
initForReadingWithData incomprehensible archive 0x62, 0x70, 0x6c, 0x69, 0x73, 0x74, 0x30, 0x30
Added: code that does not work is NSMutableData from 10+ MB
- (void)encodeWithCoder:(NSCoder*)encoder { [encoder encodeObject:self.encodedMessage forKey:@"EncodedMessage"]; //NSData [encoder encodeObject:self.data forKey:@"Data"]; //NSMutableData (10+MB) [encoder encodeObject:self.header forKey:@"Header"]; //NSString [encoder encodeObject:self.fileName forKey:@"FileName"]; //NSString [encoder encodeInt:self.dataStartIndex forKey:@"DataStartIndex"]; //int [encoder encodeInt:self.dataEndIndex forKey:@"DataEndIndex"]; //int } - (id)initWithCoder:(NSCoder*)decoder { if (self = [super init]) { self.encodedMessage = [decoder decodeObjectForKey:@"EncodedMessage"]; //NSData self.data = [decoder decodeObjectForKey:@"Data"]; //NSMutableData self.header = [decoder decodeObjectForKey:@"Header"]; //NSString self.fileName = [decoder decodeObjectForKey:@"FileName"]; //NSString self.dataStartIndex = [decoder decodeIntForKey:@"DataStartIndex"]; //int self.dataEndIndex = [decoder decodeIntForKey:@"DataEndIndex"]; //int } return self; }
When I delete self.data encoding and decoding, it always works. It also fails with a smaller self.data size. Unlike size, but content issue?
I tried to open the file, when I wrote nsmutabledata to it, the correct list editor displays an error:
"Conversion of string failed. The string is empty."
plutil also gives this error:
"$ plutil -lint nzbvortex.state nzbvortex.state: Conversion of string failed. The string is empty."