Separated DatabaseManager validation logic into separate method
This commit is contained in:
parent
8863e8f3d0
commit
25521aad74
@ -232,7 +232,7 @@ private extension DatabaseManager
|
|||||||
{
|
{
|
||||||
// MARK: - Saving -
|
// MARK: - Saving -
|
||||||
|
|
||||||
private func save()
|
func save()
|
||||||
{
|
{
|
||||||
let backgroundTaskIdentifier = RSTBeginBackgroundTask("Save Database Task")
|
let backgroundTaskIdentifier = RSTBeginBackgroundTask("Save Database Task")
|
||||||
|
|
||||||
@ -282,16 +282,12 @@ private extension DatabaseManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Notifications -
|
// MARK: - Validation -
|
||||||
|
|
||||||
dynamic func managedObjectContextDidSave(notification: NSNotification)
|
func validateManagedObjectSaveWithUserInfo(userInfo: [NSObject : AnyObject])
|
||||||
{
|
{
|
||||||
guard let managedObjectContext = notification.object as? NSManagedObjectContext where managedObjectContext.parentContext == self.validationManagedObjectContext else { return }
|
|
||||||
|
|
||||||
self.validationManagedObjectContext.performBlockAndWait {
|
|
||||||
|
|
||||||
// Remove deleted games from disk
|
// Remove deleted games from disk
|
||||||
if let deletedObjects = notification.userInfo?[NSDeletedObjectsKey] as? Set<NSManagedObject>
|
if let deletedObjects = userInfo[NSDeletedObjectsKey] as? Set<NSManagedObject>
|
||||||
{
|
{
|
||||||
let games = deletedObjects.filter({ $0 is Game }).map({ self.validationManagedObjectContext.objectWithID($0.objectID) as! Game })
|
let games = deletedObjects.filter({ $0 is Game }).map({ self.validationManagedObjectContext.objectWithID($0.objectID) as! Game })
|
||||||
|
|
||||||
@ -315,9 +311,17 @@ private extension DatabaseManager
|
|||||||
{
|
{
|
||||||
self.validationManagedObjectContext.deleteObject(collection)
|
self.validationManagedObjectContext.deleteObject(collection)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Notifications -
|
||||||
|
|
||||||
|
dynamic func managedObjectContextDidSave(notification: NSNotification)
|
||||||
|
{
|
||||||
|
guard let managedObjectContext = notification.object as? NSManagedObjectContext where managedObjectContext.parentContext == self.validationManagedObjectContext else { return }
|
||||||
|
|
||||||
|
self.validationManagedObjectContext.performBlockAndWait {
|
||||||
|
self.validateManagedObjectSaveWithUserInfo(notification.userInfo ?? [:])
|
||||||
self.save()
|
self.save()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user