I remade the program 19.4 a bit since I couldn't find the files it created. However it comes up with a SIGABRT error message. Can someone help explain why? The debugging says the error lies in line 29.
// A program that creates a dictionary instance archives it to a file
// then unarchives the file contents into a new dictionary instance
#import <Foundation/NSDictionary.h>
#import <Foundation/NSEnumerator.h>
#import <Foundation/NSObject.h>
#import <Foundation/NSStream.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSArchiver.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSDictionary *dictA = [NSDictionary dictionaryWithObjectsAndKeys:
@"Storing an object for later use", @"archiving",
@"To implement all the methods defined in a protocol", @"adopt",
@"A class created to so that other classes can inherit from it", @"Abstract class",
nil
];
NSDictionary *dictB;
if ([NSArchiver archiveRootObject: dictA toFile: @"dictA.archive"] == NO) {
NSLog(@"archiving failed");
};
dictB = [NSKeyedUnarchiver unarchiveObjectWithFile: @"dictA.archive"];
for (NSString *key in dictB) {
NSLog(@"%@: %@", key, [dictB objectForKey: key]);
}
[pool drain];
return 0;
}
And here is the error message:
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys000
sharedlibrary apply-load-rules all
[Switching to process 8579 thread 0x0]
2011-08-06 14:51:34.300 Propertylists[8579:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSKeyedUnarchiver initForReadingWithData:]: non-keyed archive cannot be decoded by NSKeyedUnarchiver'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff8e555986 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff95be5d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8e5557ba +[NSException raise:format:arguments:] + 106
3 CoreFoundation 0x00007fff8e555744 +[NSException raise:format:] + 116
4 Foundation 0x00007fff9117185b -[NSKeyedUnarchiver initForReadingWithData:] + 631
5 Foundation 0x00007fff911a103a +[NSKeyedUnarchiver unarchiveObjectWithFile:] + 129
6 Propertylists 0x0000000100000b61 main + 433
7 Propertylists 0x00000001000009a4 start + 52
)
terminate called throwing an exception(gdb)