For my iOS application using CoreData, I need to have a model where certain entities properties vary between the iPhone and iPad version of the app. To achieve this, I load a NSManagedObjectModel from a momd file located in my application bundle, using initWithContentsOfURL: . But, before the model is actually used by the storeCoordinator, I modify some entities programmatically in the model (based on information I store in a device specific plist). This used to work flawlessly on iOS4. As Apple states in its documentation,
Managed object models are editable until they are used by an object graph manager (a managed object context or a persistent store coordinator).
This does not seem to be the case in iOS5 anymore (although the documentation still states this). As soon as the model is created, with initWithContentsOfURL: for example, any attempt to modify throws an 'NSInternalInconsistencyException', reason: 'Can't modify an immutable model.' If I print the description of the model object in the debugger just after it was created, it reads 'isEditable 0', where the same reads 'isEditable 1' when running the same code on iOS4.
Using "copy" on the model the create an editable copy, as suggested by Apple, also returns a model with "isEditable 0".
I see two potential explanations for this :
- Bug . I couldn't find a matching bugreport on openradar, I will file one if necessary.
- iCloud integration. I'm not very familiar with iCloud APIs yet, but I know some kind of integration with CoreData can be set up. I imagine that maybe some automatic coordinator could access my model at the time it's created, rendering it uneditable.
I'll continue digging into these options, but if anybody has experience with this, it would be greatly appreciated.