Rectangle 27 1

iphone CoreData issue: [NSManagedObject setValue:]: unrecognized selector sent to instance?


I found that by having relations to entities I had to make sure some of my relations would be to-many, I took a screenshot so you can see what I mean, a to-many relation is indicated by the double ended arrow

Note
Rectangle 27 1

iphone CoreData issue: [NSManagedObject setValue:]: unrecognized selector sent to instance?


And don't forget to set the class name in the data model:

I am having this problem, but doing by data model provided by Xcode, all of the things you said are correctly set. My problem lies someplace else.

If you generated your NSManagedObject subclasses from the data model, everything should goes fine, although it is @dynamic, setters are be implemented by coredata, and because they are already implemented, you should not change it to synthesize. At least for me, coredata returns empty object after I change @dynamic to @synthesize.

Just to remind that, don't use capitalized variable name, it might affects the getters and setters not working properly.

Thanks. It was that last thing about class name in the model that bit me.

Note
Rectangle 27 1

iphone CoreData issue: [NSManagedObject setValue:]: unrecognized selector sent to instance?


created a new version of the Core Data Model via XCode

then re-created the NSManagedObject subclass

I had a similar issue that I was able to fix just by changing the current model version, and then changing it back. I also did a clean, though that by itself didn't help.

It was probably creating a new data model and the new subclass based on that, so I probably didn't need to clean or delete derived data...but it didn't hurt, either!

That didn't work, so I went and re-created the subclass through XCode, which is when I started getting this error ("unrecognized selector sent to instance" when setting a value for the attribute).

Note
Rectangle 27 1

iphone CoreData issue: [NSManagedObject setValue:]: unrecognized selector sent to instance?


I found that by having relations to entities I had to make sure some of my relations would be to-many, I took a screenshot so you can see what I mean, a to-many relation is indicated by the double ended arrow

Note
Rectangle 27 1

iphone CoreData issue: [NSManagedObject setValue:]: unrecognized selector sent to instance?


And don't forget to set the class name in the data model:

I am having this problem, but doing by data model provided by Xcode, all of the things you said are correctly set. My problem lies someplace else.

If you generated your NSManagedObject subclasses from the data model, everything should goes fine, although it is @dynamic, setters are be implemented by coredata, and because they are already implemented, you should not change it to synthesize. At least for me, coredata returns empty object after I change @dynamic to @synthesize.

Just to remind that, don't use capitalized variable name, it might affects the getters and setters not working properly.

Thanks. It was that last thing about class name in the model that bit me.

Note
Rectangle 27 1

iphone CoreData issue: [NSManagedObject setValue:]: unrecognized selector sent to instance?


I met the same problem and clean the project fix it!

Note
Rectangle 27 1

iphone CoreData issue: [NSManagedObject setValue:]: unrecognized selector sent to instance?


I met the same problem and clean the project fix it!

Note
Rectangle 27 1

iphone CoreData issue: [NSManagedObject setValue:]: unrecognized selector sent to instance?


-(void)setType:(NSString *)atype
{
....
[self willChangeValueForKey:@"type"];
[self setPrimitiveValue:atype forKey:@"type"];
[self didChangeValueForKey:@"type"];
} 

-(NSString *)type
{
return [self primitiveValueForKey:@"type"];
}
@dynamic type;
@property (nonatomic, retain) NSString * type;

@Graham - Just double checked, you have to synthesize if you are going to use your MO properties as Obj-C 2.0 properties. Please explain.

Case conventions are up to you but Camel Caps is nominally normal with Cocoa. But its much like an object such as Big Furry Cat becomes bigFurryCat. Follow the style in the apple examples.

Do you have corresponding @dynamic block in the .m file for these properties and

Dont use Capitalised properties, coding conventions are that properties are lowercase for the first letter at least so that when the compiler synthesises the methods.

and

if you synthesize properties you get ivar-backed properties, which you don't want with NSManagedObject subclasses. You want to allow NSManagedObject to lazily provide the accessors using the entity description.

in the background. Though you cant see that code ever.

synthesized methods, in a managed object?

Note
Rectangle 27 1

iphone CoreData issue: [NSManagedObject setValue:]: unrecognized selector sent to instance?


created a new version of the Core Data Model via XCode

then re-created the NSManagedObject subclass

I had a similar issue that I was able to fix just by changing the current model version, and then changing it back. I also did a clean, though that by itself didn't help.

It was probably creating a new data model and the new subclass based on that, so I probably didn't need to clean or delete derived data...but it didn't hurt, either!

That didn't work, so I went and re-created the subclass through XCode, which is when I started getting this error ("unrecognized selector sent to instance" when setting a value for the attribute).

Note
Rectangle 27 1

iphone CoreData issue: [NSManagedObject setValue:]: unrecognized selector sent to instance?


-(void)setType:(NSString *)atype
{
....
[self willChangeValueForKey:@"type"];
[self setPrimitiveValue:atype forKey:@"type"];
[self didChangeValueForKey:@"type"];
} 

-(NSString *)type
{
return [self primitiveValueForKey:@"type"];
}
@dynamic type;
@property (nonatomic, retain) NSString * type;

@Graham - Just double checked, you have to synthesize if you are going to use your MO properties as Obj-C 2.0 properties. Please explain.

Case conventions are up to you but Camel Caps is nominally normal with Cocoa. But its much like an object such as Big Furry Cat becomes bigFurryCat. Follow the style in the apple examples.

Do you have corresponding @dynamic block in the .m file for these properties and

Dont use Capitalised properties, coding conventions are that properties are lowercase for the first letter at least so that when the compiler synthesises the methods.

and

if you synthesize properties you get ivar-backed properties, which you don't want with NSManagedObject subclasses. You want to allow NSManagedObject to lazily provide the accessors using the entity description.

in the background. Though you cant see that code ever.

synthesized methods, in a managed object?

Note