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

后端 未结 8 610
温柔的废话
温柔的废话 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 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

提交回复
热议问题