Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

9. Migrating and Optimizing with Core Da... > Core Data can “lightly” migrate data

Core Data can “lightly” migrate data

Lightweight data migration is a powerful Core Data tool that allows you to cleanly update your underlying data to match a new data model without needing a mapping model. It only works with basic data changes: adding new attributes, changing a required attribute to an optional one, or making an optional attribute required with a default value. It can also handle limited renaming of attributes, but that gets trickier.

Automatic data migration happens at runtime, which means that your app needs to know that it’s going to happen so that the data can be migrated. You’ll do that in the AppDelegate:

image with no caption

Test Drive

After adding the code to the app delegate, build and debug...

Note

If you run into issues here, try Build-> Clean first, then Build and Debug. Strangely, Xcode doesn’t always properly recompile the first time you version your model, but cleaning should fix it.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial