I am encoding my object and saving it to a file as follows:
[NSKeyedArchiver archiveRootObject:self.parent toFile:@"gameScene.plist"];
and decoding it as follow:
scene = [[NSKeyedUnarchiver unarchiveObjectWithFile:@"gameScene.plist"] retain];
In simulator the above decoding code invokes my class’s initWithCoder method properly. But when I run the same in device, the ‘initWithCoderis not called nor theinit` method and a ‘nil’ object is returned.
Could anyone please explain whats wrong here?
EDIT: For testing purposes, I gave same set of statements in both init and initWithCoder, instead of decoding the subobjects in initWithCoder and commented out all the encoding in my encodeWithCoder.
Maybe because you can’t write to the root directory on an iOS device? I think that a path of
@"gameScene.plist"really means/gameScene.plist, which is not writable on an iOS device, but would be allowed on OS X. The-archiveRootObject:toFile:method is probably returningNOhere, indicating that the file wasn’t created successfully.You may want to do something similar to this: