I have the following problem while unarchiving a file, which contains an xml string.
It crashes at the following line:
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
'data' (27580 bytes) comes from:
NSMutableData *data = [NSData dataWithContentsOfURL:url];
And the crash i got:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSKeyedUnarchiver initForReadingWithData:]: incomprehensible archive (0x62, 0x70, 0x6c, 0x69, 0x73, 0x74, 0x30, 0x30)'
The file was created that way:
NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
NSData *project = [ProjectToXML convertProject:SelectedProject];
[archiver encodeObject:project forKey:kProjectKey];
[archiver finishEncoding];
'convertProject:' does basically create an NSMutableString with the xml content and converts it to NSData that way ('encoding' is utf-8):
[xmlString dataUsingEncoding: CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((__bridge CFStringRef)encoding)) allowLossyConversion:NO];