Describe lightweight vs heavyweight Core Data migration and a heavyweight example

This tests inferred versus manual Core Data migrations. Contrast lightweight additive changes with heavyweight transforms like entity splits, citing promoting a string to a new entity. A red flag is claiming renames always need custom mapping.
What's really being asked
This question evaluates whether you understand Core Data schema versioning and the boundary between automatic lightweight migration and manual heavyweight migration. Interviewers want to see that you know the framework can infer simple additive changes but that complex or destructive changes require an explicit mapping model or custom migration policy. They also care whether you recognize the operational cost of heavyweight migrations in production.
The full answer
First, define lightweight migration as the automatic path enabled by setting NSMigratePersistentStoresAutomaticallyOption and NSInferMappingModelAutomaticallyOption in the persistent store options. This path works when changes are additive and non-destructive, such as adding a new entity, adding an optional attribute, or adding a new optional relationship. Second, define heavyweight migration as any change that Core Data cannot infer automatically, which forces you to create a mapping model in Xcode or implement a custom NSEntityMigrationPolicy subclass. Destructive changes that trigger this include removing an attribute, changing an attribute type, adding a non-optional attribute without a default value, splitting one entity into two, merging entities, or transforming data in a way that requires logic. Third, discuss the practical implications: lightweight migrations run quickly and use little extra space, while heavyweight migrations may effectively duplicate the entire store and should be performed on a background queue to avoid blocking the user interface. Fourth, mention that SwiftData simplifies many migration scenarios but still respects the same underlying rules for complex transforms.
The mistakes people make
Claiming that renaming an entity or property always requires heavyweight migration. In reality, Core Data supports lightweight renaming via the renamingIdentifier. Saying that adding a new entity or optional field requires heavyweight migration is also incorrect. Another red flag is suggesting you can simply delete the existing store and recreate it in a production app without acknowledging catastrophic data loss. Some candidates also incorrectly state that SwiftData eliminates heavyweight migrations entirely, when in fact complex data transforms still require thoughtful migration strategies.
What usually comes next
How would you execute a heavyweight migration without blocking the main thread? What is a mapping model and how do you create one in Xcode? How do you handle a migration that requires splitting a single entity into two related entities with foreign keys? What performance considerations matter when migrating a store containing ten million records? How do you validate that a migration succeeded before swapping the new store in place?
A concrete example
A classic heavyweight scenario is refactoring a Book entity that stores authorName as a string into a schema with a separate Author entity and a relationship. Core Data cannot automatically infer how to turn each unique authorName string into a distinct Author managed object and then wire the relationship from each Book to the correct Author. You must supply a mapping model and likely a custom migration policy that iterates the old Book entities, creates or deduplicates Author objects based on the string value, assigns the relationship, and cleans up the old attribute.
Interview question
Which schema change requires a heavyweight Core Data migration instead of lightweight automatic migration?
- a.Replacing Book's authorName string with a separate Author entity and a relationshipCorrect
- b.Adding an optional pageCount attribute to an existing Book entity
- c.Introducing a new optional Review entity with a relationship to Book
- d.Renaming the title property to bookTitle using a renamingIdentifier
Why? this is the answer
Promoting a string attribute to a new entity with a relationship is a destructive transform that Core Data cannot infer, forcing a custom mapping model. Renaming with renamingIdentifier is lightweight, so it does not require a heavyweight migration.
Just read this? Test yourself on what you have been reading.
Read the original → developer.apple.com
- #ios
- #core-data
- #swiftdata
- #data-persistence
- #schema-migration
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on ios — each one lists the topics its interview covers.
See open roles