[英]How to load & save custom object to iOS and OSX?
我有一个在iOS应用程序和OSX应用程序中都使用过的自定义对象。 看起来像这样:
@interface Preset : NSObject
#if TARGET_OS_IPHONE
@property (nonatomic, strong) UIImage *thumbnail;
@property (nonatomic, strong) UIImage *customThumbnail;
#else
@property (nonatomic, strong) NSImage *thumbnail;
@property (nonatomic, strong) NSImage *customThumbnail;
#endif
@property (nonatomic, strong) NSDictionary *parms;
@property (nonatomic, strong) NSString *name;
@end
我希望无论我在哪里创建对象,都可以在iOS和OSX中加载和保存该对象。
我打算实现NSCoding方法来进行简单的加载和保存,但是由于NSImage和UIImage之间的差异,我想到我无法在OSX上创建Preset文件并在iOS中使用它。
我敢肯定有一个简单的方法可以做到这一点,但是我看不到。
任何人?
谢谢!
将UIImage
或NSImage
转换为包含图像的PNG表示形式的NSData
。 然后在您的NSCoding
设置中使用该NSData
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.