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
„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 [fusion_builder_container hundred_percent=“yes“ overflow=“visible“][fusion_builder_row][fusion_builder_column type=“1_1″ background_position=“left top“ background_color=““ border_size=““ border_color=““ border_style=“solid“ spacing=“yes“ background_image=““ background_repeat=“no-repeat“ padding=““ margin_top=“0px“ margin_bottom=“0px“ class=““ id=““ animation_type=““ animation_speed=“0.3″ animation_direction=“left“ hide_on_mobile=“no“ center_content=“no“ min_height=“none“][[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.