Crystal
Crystal

Reputation: 29518

recreate NSManagedObject subclasses when the model changes in the model editor

I was wondering if there was a way to update the NSMangedObject subclass after you change a property or add a field in the Core Data model editor. Sometimes I add a field, or realize that I accidentally put integer as the type instead of string, but my NSManagedObject subclass was already created. So instead of manually going in and adding those fields, I was wondering if there was a way for Xcode to just update the model? Thanks.

Upvotes: 2

Views: 1230

Answers (2)

Monolo
Monolo

Reputation: 18253

Others have explained how you can re-create the files, but do notice that the files overwrite the original ones, so if you have made any manual additions (extra methods, for instance) you're going to lose them. A backup can be useful before you write the files out again.

If you do need to add functionality to an NSManagedObject subclass, consider using categories in separate files. That way you can tweak your class in the Core Data editor, re-export your files and avoid losing your additional functionality because it is saved in the category files.

Upvotes: 8

AdamG
AdamG

Reputation: 3718

I believe you just have to go to file -> new -> file -> core data under iOS -> NSManagedObject subclass and it is self explanatory from there.

You can also check out mogenerator, an open api that helps manage a lot more of core data for you.

Upvotes: 0

Related Questions