Skip to content
This repository was archived by the owner on Nov 24, 2021. It is now read-only.

Add notification for context saved #119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Source/DATAStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ import CoreData
} else {
let contextBlock: @convention(block) () -> Void = {
self.mainContext.mergeChanges(fromContextDidSave: notification)
NotificationCenter.default.post(name: .NSManagedObjectContextMergedChanges, object: context)
}
let blockObject: AnyObject = unsafeBitCast(contextBlock, to: AnyObject.self)
self.mainContext.perform(DATAStack.performSelectorForBackgroundContext(), with: blockObject)
Expand All @@ -415,6 +416,12 @@ import CoreData
}
}

public extension Notification.Name {
static var NSManagedObjectContextMergedChanges: Notification.Name {
return .init("NSManagedObjectContextMergedChanges")
}
}

extension NSPersistentStoreCoordinator {
func addPersistentStore(storeType: DATAStackStoreType, bundle: Bundle, modelName: String, storeName: String?, containerURL: URL, isExcludedFromBackup: Bool) throws {
let filePath = (storeName ?? modelName) + ".sqlite"
Expand Down