NSKeyedUnarchiver initForReadingWithData: incomprehensible archive failure

I have the following problem when unpacking a file that contains an xml string.

Failure in the following line:

NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data]; 

'data' (27580 bytes) comes from:

 NSMutableData *data = [NSData dataWithContentsOfURL:url]; 

And the accident I got:

Application termination due to an uncaught exception 'NSInvalidArgumentException', reason: * * - [NSKeyedUnarchiver initForReadingWithData:]: incomprehensible archive (0x62, 0x70, 0x6c, 0x69, 0x73, 0x74, 0x30, 0x30) '

The file was created this 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:' basically creates an NSMutableString with xml content and converts it to NSData this way ('encoding' is utf-8):

 [xmlString dataUsingEncoding: CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((__bridge CFStringRef)encoding)) allowLossyConversion:NO]; 
+6
source share

Source: https://habr.com/ru/post/958547/


All Articles