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

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

    I had the same problem and I found a not-so-elegant solution. It seems that

    [NSEntityDescription insertNewObjectForEntityForName:@"myEntity" inManagedObjectContext:myManagedObjectContext];
    

    creates an old version of myEntity that does not have the attributes of the most up-to-date version. So I changed the name of myEntity in the old version of the model to myEntityOld and I did not get the error any more.

    I suspect that there is an elegant way to do the same thing in XCode by setting a property of NSManagedObject or NSEntityDescription.

提交回复
热议问题