【发布时间】:2015-11-17 13:42:47
【问题描述】:
我正在尝试在 CoreData 中存储图像数组。我知道最好的方法是将图像存储在应用程序的目录中并将指向它们的链接存储在 CD 中,但我不想完全重新组织我的应用程序并将二进制数据存储在 CD 中。
我已经弄清楚如何存储单个图像:
在 xcdatamodeld 中,我创建了二进制类型的 thumbnailImageData。
在我的 .h 中,我将其显示为 UIImage 类型:
@property (nonatomic, retain, readonly) UIImage* thumbnailImage;
在 .m 中,我已声明 thumbanilImageData 并将 thumbnailImage 设置为动态并在 getter 和 setter 中将 thumbnailImage 重新格式化为二进制:
@implementation galleryItem {
NSData* thumbnailImageData;
}
@dynamic thumbnailImage;
-(UIImage *)thumbnailImage {
UIImage* returnThumbnailImage = [UIImage imageWithData:thumbnailImageData];
return returnThumbnailImage;
}
- (void)setThumbnailImage:(UIImage *)thumbnailImage {
thumbnailImageData = UIImagePNGRepresentation(thumbnailImage);
}
我怎样才能做同样的事情来存储/设置/获取图像数组?
【问题讨论】:
标签: ios objective-c arrays core-data