I encounter the same issue in Xcode 4.1 with ARC support:
BOOL isFileExist = [[NSFileManager defaultManager] fileExistsAtPath:filePath]; NSAssert(isFileExist, @"filePath does not exist"); NSKeyedUnarchiver* coder = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath]; // nil NSData* data = [[NSFileManager defaultManager] contentsAtPath:filePath]; coder = [NSKeyedUnarchiver unarchiveObjectWithData:data]; // nil coder = [[NSKeyedUnarchiver alloc] initForReadingWithData:data]; // OK!!!
This seems to be a bug in cocoa -touch.
Edit:
It is supposed to behave like this, and this is not a mistake. But I agree that naming easily leads to errors.
[[NSKeyedUnarchiver alloc] initForReadingWithData:] returns an instance of NSKeyedUnarchiver .
[NSKeyedUnarchiver unarchiveObjectWithData:] returns the root object. This is the conviencen method for:
NSKeyedUnarchiver *coder = [[self alloc] initForReadingWithData:arg2]; id object = [coder decodeObjectForKey:@"root"];
poGUIst
source share