.h文件:@dynamic如何設置屬性?
@interface TaskTypeEntity : NSManagedObject
@property (nonatomic, retain) UIColor *color;
@property (nonatomic, retain) UIImage *image;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSNumber * status;
@property (nonatomic, retain) NSSet *task;
@property (nonatomic, retain) NSSet *taskCount;
@end
M檔:
@implementation TaskTypeEntity
@dynamic color;
@dynamic image;
@dynamic name;
@dynamic status;
@dynamic task;
@dynamic taskCount;
- (void) add:(TaskTypeEntity*)data
{
TaskTypeEntity *taskTypeEntity = [NSEntityDescription insertNewObjectForEntityForName:ENTITY_NAME inManagedObjectContext:content];
taskTypeEntity.name = data.name;
taskTypeEntity.image = data.image;
taskTypeEntity.color = data.color;
BOOL result = [content save:nil];
if (result) {
NSLog(@"success%@", data);
}else{
NSLog(@"fail");
}
}
@end
當設置該屬性,它不工作:
TaskTypeEntity *taskTypeEntity = [TaskTypeEntity alloc];
taskTypeEntity.name = @"dfdfd";
[taskTypeModel add:taskTypeEntity];
錯誤: *終止應用程序由於未捕獲的異常「NSInvalidArgumentException」,重新ASON: ' - [TaskTypeEntity的setName:]:無法識別的選擇發送到實例0x8a7b070'
請幫幫我,謝謝
這不是辦法創建實體(儘管它不是創建任何Objective-C對象的方式)。請閱讀Apple的核心數據指南。 – Desdenova
[核心數據編程指南介紹](https://developer.apple.com/library/mac/documentation/cocoa/conceptual/coredata/cdProgrammingGuide.html) – Desdenova
謝謝,我的英文不是很好,但我會仔細閱讀 – user3374273