可能是因为您无法写入 iOS 设备上的根目录?我认为@"gameScene.plist"
真的意味着路径/gameScene.plist
,它在iOS设备上不可写,但在OS X上是允许的。该-archiveRootObject:toFile:
方法可能返回NO
此处,表明文件未成功创建。
你可能想做类似的事情:
NSURL *documentsURL = (NSURL *) [[[NSFileManager defaultManager] URLsForDirectory: NSDocumentDirectory inDomains: NSUserDomainMask] lastObject];
NSString *filePath = [[documentsURL path] stringByAppendingPathComponent: @"gameScene.plist"];
BOOL success = [NSKeyedArchiver archiveRootObject: self.parent toFile: filePath];
NSLog(@"Archive Success... %s", (success) ? "YES" : "NO");
NSLog(@"File Exists... %s", [[NSFileManager defaultManager] fileExistsAtPath: filePath] ? "YES" : "NO");
id unarchivedObject = [[NSKeyedUnarchiver unarchiveObjectWithFile: filePath] retain];
NSLog(@"Unarchive Success... %s", (unarchivedObject != nil) ? "YES" : "NO");
NSLog(@"Equal Objects... %s", [self.parent isEqual: unarchivedObject] ? "YES" : "NO");