Basic app layout using the navigation controller template with core date:
Delegate: persistenceCoordinator, managedObjectModel, managedObjectContext
- RootView: managedObjectContext (from delegate), addManagedObjectContext (using the pattern from the templates), fetchResultsController
- Add/Edit view (a hierarchy for adding Object A & its B)
I have two objects, A & B that share a 1-to-1 relationship/inverse relationship
Using the pattern from the templates the app:
- Creates an addManagedObjectContext
- Inserts an A entity
- Pushes on the Add/Edit A view (having passed it the inserted entity)
EXCEPTION STEPS 1:
If I simply fill in the A attributes and save everything works fine.
- The object is inserted into the database (verified with sqlite3 on the command line)
- The fetchResultsController updates the list view
- I can close and open the app (full close/open not just app switch) and the list view will re fetch correctly
If I then Edit A, I can select Add B and an add B view is pushed on (and passed the A entity)
- Fill in B details and save
- B is inserted into A's managedObjectContext, the relationship is set, and the context is saved
- The view pops off and all appears well
- The objects are both in the database with the correct relationship
- I can reload the record and see the relationship, make edits etc
- EXCEPTION: If I close/reopen the app, so as to trigger a fetch, then the error mentioned in the title will occur.
EXCEPTION STEPS 2:
If I fill in the A attributes AND the B attributes in the initial "add"
- Saving B triggers a full save of A's context (as above)
- Saving A saves via the delegate relationship set up by the template (and merges the result into the main managedObjectContext etc)
- The objects are inserted into the database correctly
- However the fetchResultsController DOES NOT update to show the new records
- EXCEPTION: If I close/reopen the app, so as to trigger a fetch, then the error mentioned in the title will occur.
I've tried saving A first, adding a separate context for B etc etc. I'm confused to say the least. Any help would be greatly appreciated.
Cheers, Ryan