开发者

Reading Cocoa (not Cocoa Touch) archives on iPhone

开发者 https://www.devze.com 2022-12-20 14:25 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号