开发者

Core Data set Attributes

开发者 https://www.devze.com 2023-01-19 21:52 出处:网络
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

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".

0

精彩评论

暂无评论...
验证码 换一张
取 消