Core Data set Attributes
I'm trying to set attributes with Core Data but it won't work. Every time I call the method setAveScore
it throws the error [Stats setAveScore:]: unrecognized selector sent to instance 0x3364c0
Any idea what is going wrong?
The call:
Stats *sObj = [Stats alloc];
NSNumber *foo = [[NSNumber alloc ]initWithInt:1];
sObj.aveScore = foo;
The Core Data class:
@interf开发者_如何学Pythonace Stats : NSManagedObject
{
}
@property (nonatomic, retain) NSNumber * aveScore;
@end
#import "Stats.h"
@implementation Stats
@dynamic aveScore;
@end
The whole errormessage:
-[Stats setAveScore:]: unrecognized selector sent to instance 0x1494b0
Exception detected while handling key input.
-[Stats setAveScore:]: unrecognized selector sent to instance 0x1494b0
sObj is not initialized correctly. To get a Core Data managed object, you have to insert it in to a managed object context, like so:
NSManagedObjectContext context = ...
Stats *sObj = [NSEntityDescription insertNewObjectForEntityForName:@"Stats" inManagedObjectContext:context];
That's assuming your entity name is @"Stats".
精彩评论