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

后端 未结 8 609
温柔的废话
温柔的废话 2021-02-05 08:29

I just started with CoreData yesterday, and I\'m going crazy :( I created a project that uses CoreData (ticked the box -use CoreData). Created the entities, and then created the

相关标签:
8条回答
  • 2021-02-05 08:59

    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

    enter image description here

    0 讨论(0)
  • 2021-02-05 09:01

    Two possible problems

    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.

    @property (nonatomic, retain) NSString * type; in .h

    and

    @dynamic type; in .m

    becomes something like

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

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

    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.

    EDIT - change @synthesize to @dynamic

    0 讨论(0)
提交回复
热议问题