【发布时间】:2015-04-17 06:51:39
【问题描述】:
我想将我的 imageArray 添加到 coredata 中作为可转换的,但这不能正确存储。
我的保存按钮编码。
- (IBAction)saveButton:(id)sender {
NSManagedObjectContext *context = [self managedObjectContext];
NSManagedObject *newEntry = [NSEntityDescription insertNewObjectForEntityForName:@"FoodInfo" inManagedObjectContext:context];
NSAttributeDescription *messageType = [[NSAttributeDescription alloc] init];
[messageType setName:@"photos"];
[messageType setAttributeType:NSTransformableAttributeType];
[imagesForShow addObject:messageType];
NSError *error = nil;
if (![context save:&error]) {
NSLog(@"Unable to save context for class" );
} else {
NSLog(@"saved all records!");
[context save:nil];
}
//[newEntry setValue:imagesForShow forKey:@"images"];
}
- 这里的“imagesForShow”是我的图像数组。
当我要获取这个图像数组时,这个显示为 nil
- (void)viewDidLoad {
[super viewDidLoad];
NSManagedObjectContext *context = [self managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc]initWithEntityName:@"FoodInfo"];
[request setReturnsObjectsAsFaults:NO];
arrayForPhotos = [[NSMutableArray alloc]initWithArray:[context executeFetchRequest:request error:nil]];
// Do any additional setup after loading the view.
}
这段代码我做错了什么。谢谢。
【问题讨论】:
-
你想对属性描述做什么?阵列在哪里配置?你看到什么错误/结果?为什么要将图像存储在核心数据中?
-
这是关于图像数组的描述。错误不过是在我要获取时显示为零。我想要将来从照片库中选择的图像。如果有任何其他方法可以将图像数组存储在核心数据中,请发布。
-
如果它们在照片库中,为什么不存储资产 URL?