I have made a data model, and now I've made a 2nd version. All of the generated NSManagedObjects mapped to that data model are all version 1. Is there some way to update them to v2 without deleting them and then saying having them generated again?
views:
228answers:
1iPhone Core Data how to update the NSManagedObjects .h & .m after making changes to the data model
If you have two versions of your model you need to either create a mapping model between the two versions or you need to turn on automatic migration if the changes are simple enough for Core Data to resolve.
I would suggest reviewing Apple's documentation on the subject of Core Data migration.
update
I'm using auto migration. But say I have a person entry in v1 that just is last name and first name. In v2 I added date of birth. After making the data model of v1 I told Xcode to generate the NSManaged objects (in this example Person.m) now I've made v2 model with auto migration set up. How do I update Person.m to add DOB without deleting and then adding it again, or adding DOB manually?
The NSManagedObject
will already have it in there, if you want to add the properties (as opposed to just the attributes) then just type in the two lines of code into your NSManagedObject
subclass.
update
Other option, which I highly recommend, is to use mogenerator instead of the built-in code generator. mogenerator will keep the files up to date after model changes.