Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Data Entity rename

I created a Core Data Entity called "MyObject". I then renamed the entity "ThatObject". But every time I create a NSManagedObject subclass, it still creates the .h/.m file as MyObject.

I take the "MyObject" files and just rename them to "ThatObject" and everything works, but its annoying to have to do that everytime i alter the entity attributes.

Any idea how to fix this?

like image 297
Padin215 Avatar asked Mar 11 '13 16:03

Padin215


2 Answers

When you are renaming the entity make sure you rename both Name and Class in the Data Model Inspector. In my project, if both are renamed the new auto-generated NSManagedObject subclasses are created with the new names.

Dialog options to rename entity and class

like image 160
Pliskin Avatar answered Sep 21 '22 19:09

Pliskin


For future readers: Pay attention to the model version though, if your app is already published, updating the app may break the database schema on your users devices which results in a crash on launch. Core Data can automatically find a migration for this easy case, you can find more information on lightweight migrations here. You basically have to set a renaming ID so CD knows what got renamed to what even if skipping versions in between.

like image 22
bjrne Avatar answered Sep 19 '22 19:09

bjrne