我有实体:
@class CDCustomItem;
@interface CDCustomItem : NSManagedObject
@property (nonatomic, retain) CDCustomImage *image;
@end
和CDCustomImage
实体:
@class CDCustomImage;
@interface CDCustomImage : NSManagedObject
@property (nonatomic, retain) NSString * url;
@property (nonatomic, retain) CDCustomItem *itemParent;
@end
CDCustomImage.image和CDCustomImage.itemParent的类型为“To One”
将图像插入CDCustomItem后,它会显示在NSLog
:
image = "0x79e59df0 <x-coredata:///CDCustomImage/t765B46F3-87B1-4C09-A108-6584F4E58DDB214>";
但是当我尝试NSLog(@"%@", CDCustomItem.image)
时,它会返回null
为什么会这样?怎么解决?请帮忙
编辑1: 所有操作都在一个线程中
编辑2: 以下是如何将图像插入CDCustomItem的代码:
CDCustomImage *image = [self insertImage:[jsonDict objectForKey:@"image"]];
item.image = image;
- (CDCustomImage *)insertImage:(NSDictionary *)jsonDict {
CDCustomImage *entity = [self insertEntityWithName:[CDCustomImage description]];
[self fillFieldsForImage:entity dict:jsonDict];
return entity;
}
- (void)fillFieldsForImage:(CDCustomImage *)entity dict:(NSDictionary *)jsonDict {
entity.url = [jsonDict valueForKey:@"url"];
}