I'm writing an iPhone app that is mainly centered around grid patterns, so I have a Pattern class which contains an NSMutableArray of NSMutableArrays. This class implements NSCoding, and it seems the following code works just fine in my iPhone app:
GridPattern * pattern = [GridPattern patternWithWidth:8 height:8];
[pattern setValueAtColumn:0 row:7 value:1];
[NSKeyedArchiver archiveRootObject:pattern toFile:@"test.pat"];
pattern = [NSKeyedUnarchiver unarchiveObjectWithFile:@"test.pat"];
If I debug the code above, I find after stepping over line 4, that I have a GridPattern object with the appropriate value set for column 0, row 7.
I have also written a Cocoa OSX application intended for creating patterns for the iPhone app, which also uses the same GridPattern class. It can also load and save the patterns successfully.
What I wanted to do was:
- create and save the patterns in the OS X app
- add the pattern files into Resources group in XCode for the iPhone app; (I added it as
test.pat
) unarchive the patterns in my iPhone app, using code such as:
pattern = [NSKeyedUnarchiver unarchiveObjectWithFile:@"test.pat"];
However, when I try to unarchive the objects from this file, all that is returned is nil
. I thought I might have had the file path wrong and also tried @"Resources/test.pat"
to no avail.
Am I simply referring to the file incorrectly? Or are archived objects simply not cross-platform? Is this whole approach just plain wrong? If so, how would you do it?