简体   繁体   中英

Core Data: how to turn on versioning?

When I create a new project, and create a core data model, on right hand side panel, I can see a sectioned called 'Versioned Core Data Model' and a drop down list named 'Current', with only one item in the list, does this mean versioning is switched on? I ask because someone told me I need to go to Editor->Add Model Version and add another model version, then the Model.xcdatamodeld file in LHS will have a small arrow and two xcdatamodel files below it, versioning is NOT switched on until I do this, is this correct?

To add a new version of a model, it is correct that you go to Editor->Add Model Version Create a new name, say, xxx v2, and base it on a previous version.

Once you've got your new version, you can add, change and remove entities.

You'll then want to select your new version from the dropdown list on the sidebar (whatever you called it when you created a version), and also update any subclassed NSManagedObjects.

Finally, you'll need to create a mapping between the old version and the new one. (File -> New -> File -> Core Data -> Mapping Model)

Note: You'll only need to do this when you have shipped your app, and later want to change your model for an update. From your question, it sounded like you just started a new project? (It's worth noting that a versioned core data model doesn't have anything to do with Source control, just in case you were confused by that)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM