Fighting NSManagedObjectModels configurations

//Fighting NSManagedObjectModels configurations

Fighting NSManagedObjectModels configurations

Whenever you add an NSManagedObjectModel into your project it comes with a Default Configuration. I’m sure you’ve noticed it but probably never dived into the burrow. I had when Apple rejected my app for violating the iCloud storage guidelines.
As quick as you add configurations (the default one can’t be edited nor deleted) and assign entities to it, you’ll notice that even Apple make you think that inserting new objects into your model, those object get assigned to the right store file it is not the case.

– (void)assignObject:(id)object toPersistentStore:(NSPersistentStore *)store
Special considerations
„It is only necessary to use this method if the receiver’s persistent store coordinator manages multiple writable stores that have object’s entity in their configuration. Maintaining configurations in the managed object model can eliminate the need for invoking this method directly in many situations. If the receiver’s persistent store coordinator manages only a single writable store, or if only one store has object’s entity in its model, object will automatically be assigned to that store.“

You might thing I’ve added my and only my configurations to the store coordinator but as soon as you insert new object into the model (I guess) core data looks in your managed object model available configurations (including the default one) and finds at least 2 configurations for your newly created object. So this might be the reason that for newly created objects

[[object objectID] persistentStore] returns nil.

So I wrote a category on NSEntityDescription to overcome that problem.
The method name is quite long but I wanted to make sure that you understand that this method skips the default configuration whenn looking for you entities store file.
NOTE: Core data allows you to have the same entity in different configurations. So might be forced to use other means when assigning the peristent stores.

By |2018-06-06T20:31:56+00:00Montag, Juli 2nd, 2012|Development|0 Comments

About the Author:

Leave A Comment

For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

I agree to these terms.