我正在尝试使用Core Data设置属性,但它不起作用。每当我调用方法setAveScore
时,它都会抛出错误[Stats setAveScore:]: unrecognized selector sent to instance 0x3364c0
知道出了什么问题吗?
电话:
Stats *sObj = [Stats alloc];
NSNumber *foo = [[NSNumber alloc ]initWithInt:1];
sObj.aveScore = foo;
核心数据类:
@interface Stats : NSManagedObject
{
}
@property (nonatomic, retain) NSNumber * aveScore;
@end
#import "Stats.h"
@implementation Stats
@dynamic aveScore;
@end
整个错误消息:
-[Stats setAveScore:]: unrecognized selector sent to instance 0x1494b0
Exception detected while handling key input.
-[Stats setAveScore:]: unrecognized selector sent to instance 0x1494b0
答案 0 :(得分:1)
sObj未正确初始化。要获取Core Data托管对象,必须将其插入到托管对象上下文中,如下所示:
NSManagedObjectContext context = ...
Stats *sObj = [NSEntityDescription insertNewObjectForEntityForName:@"Stats" inManagedObjectContext:context];
假设您的实体名称是@“Stats”。