Student pilot here. I believe I can have two managed object models (separate .xcdatamodeld files) representing two unrelated sets of entities/attributes/relations (e.g., model 1 for Employees/Departments and model 2 for Products/Customers) and load them via

+(NSManagedObjectModel *)modelByMergingModels:

and lightweight migration will work within each model. (Correct?) I only want to use one store, which is recommended for efficiency (and because it will be in iCloud().

However, if I need a new set of entities down the road, can I simply add a new model file representing the new set of entities/attributes (that are unrelated to the first two models -- e.g., Invoices/Payments)? Will Core Data's lightweight migration automatically create those entities when it sees the new entities?

有帮助吗?

解决方案

Yes, this works. However it seems to represent unnecessary complexity. You're using multiple models when one would do the job. Sure, it'll work, but why make things harder than necessary? By putting everything in one persistent store file, you're not actually keeping the data separate, so using multiple models isn't getting you anything except a little more work.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top