Reading Cocoa (not Cocoa Touch) archives on iPhone
If I have a file that was written by Cocoa on a Mac, using NSKeyedArchiver, are there any tricks to reading it on iPhone OS? NSKeyedArchiver exists on both platforms, but the Mac version might archive an NSColor, and iPhone can only unarchive UIColor.
There’s setClassName:forClass: but I don’t think that helps.
I don’t think开发者_JS百科 it’s literally going to be possible to convert the NSColor (or most other classes), but I was wondering if there were some tricks.
(I have had success with archived NSStrings.)
Since NSColor and such don't actually exist on the iPhone, there's nothing stopping you from creating an NSFoo class that's either a subclass of UIFoo (if their API are compatible) or wrapping a UIFoo internally.
It's possible to have NSKeyedUnarchiver
redirect unarchiving of certain class names:
[NSKeyedUnarchiver setClass:[MyColor class] forClassName:@"NSColor"]
If possible, avoid archiving objects between platforms NSKeyedArchiver
/NSKeyedUnarchiver
are not designed to produce interchange formats.
精彩评论