I am completely at this and out of ideas for about a week now.
I have a CoreData stack with multiple coordinators and managed contexts, and I am attempting to implement a logout feature in the app.
The tableviews that interact with CoreData is inside a TabBarController, and there are on-boarding (i.e. registration & login) NavigationControllers and ViewControllers that lead up to it.
What I am attempting to implement is a logout (i.e. unwind to initial ViewController. I have tried so far - to no avail:
- reset() each managedObjectContext individually
- every possible combination of tableView.beginUpdates(), tableView.endUpdates(), tableView.reloadData(), frc.performFetch()
- Delete each entity in each managedObject then reset() each managedObjectContext individually
- set tableView, fetchedResultsController delegates and datasource to nil, then to self on viewDidLoad()
- Having a NSNotification that fires just before logging out - deleting everything in CoreData and saving it, effectively updating and emptying the table.
- a whole lot more
Is there a way to completely reset CoreData so when the user unwinds to initial ViewController and re-run the whole process I won't get
Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. attempt to insert row 9 into section 0, but there are only 9 rows in section 0 after the update with userInfo (null)
or in the case I emptied the table via Notifications:
Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. attempt to insert row 9 into section 0, but there are only 0 rows in section 0 after the update with userInfo (null)
CoreData works just fine if I logout, close the app, and restart. No errors this way. This makes me think there is a way to completely reset CoreData (and any tableViews, fetchedResultsControllers associated with it) or reset to a pristine state when unwinding to the initial ViewController.
or should I just duplicate the storyboard and have a separate set of on-boarding viewControllers just for logging out so CoreData doesn't reinitialize?
Any ideas? Thanks.