Commit ffbfcbde authored by Ben Jackson's avatar Ben Jackson
Browse files

Fix crash when logging out

When logging out, we attempted to clear out some core data entities
named "Suggestion", but this didn't exist, leading to an abort.

It's not clear why "Room" and "Suggestion" were the only things cleared,
but it makes sense to clear all of the entities on logout, as they will
be reloaded anyway. Delegate the list to the JsonToDatabase, so as to
avoid these getting out of sync again (albeit not in the ideal way).
parent 56bb1d96
......@@ -58,7 +58,9 @@ class CoreDataSingleton {
func deleteAllObjects(_ saveCallback: @escaping SaveCallback) {
workerManagedObjectContext.perform {
for entityName in ["Room", "Suggestion"] {
// FIXME: Really we should ask JsonToDatabase to perform these deletes rather than
// just asking it for the list
for entityName in JsonToDatabase.managedObjectEntitiesToClearOnLogout() {
do {
try self.deleteAllObjects(forEntity: entityName, context: self.workerManagedObjectContext)
} catch {
......@@ -13,6 +13,16 @@ class JsonToDatabase {
private let adminGroupCollectionFactory: ModelFactory<AdminGroupCollection>
private let userSuggestionCollectionFactory: ModelFactory<UserSuggestionCollection>
public static func managedObjectEntitiesToClearOnLogout() -> [String] {
return [ "Room",
init (context: NSManagedObjectContext) {
self.context = context
roomFactory = ModelFactory(entityName: "Room", context: context)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment