views:

19

answers:

1

Hi there,

I'm trying to set attributes with Core Data but it won't work. Every time I call the mehtod 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:

@interface 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
+1  A: 

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

Daniel Dickison
What does those three dots mean? Saw this several times before and tried it without success. `+entityForName: could not locate an NSManagedObjectModel for entity name 'Stats'`. My entity is, as you thought, Stats.
lueda
The ... means if you don't know what goes there, you need to start at the beginning and read through the [Core Data Programming Guide](http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/CoreData/cdProgrammingGuide.html#//apple_ref/doc/uid/TP40001075).
Daniel Dickison