This repository was archived by the owner on Nov 24, 2021. It is now read-only.
File tree 1 file changed +8
-0
lines changed
1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ import CoreData
27
27
28
28
private var containerURL = URL . directoryURL ( )
29
29
30
+ private let backgroundContextName = " DATAStack.backgroundContextName "
31
+
30
32
/**
31
33
The context for the main queue. Please do not use this to mutate data, use `performInNewBackgroundContext`
32
34
instead.
@@ -232,6 +234,7 @@ import CoreData
232
234
*/
233
235
@objc public func newBackgroundContext( ) -> NSManagedObjectContext {
234
236
let context = NSManagedObjectContext ( concurrencyType: DATAStack . backgroundConcurrencyType ( ) )
237
+ context. name = backgroundContextName
235
238
context. persistentStoreCoordinator = self . persistentStoreCoordinator
236
239
context. undoManager = nil
237
240
context. mergePolicy = NSMergeByPropertyStoreTrumpMergePolicy
@@ -373,6 +376,11 @@ import CoreData
373
376
374
377
// Can't be private, has to be internal in order to be used as a selector.
375
378
@objc func backgroundContextDidSave( _ notification: Notification ) throws {
379
+ let context = notification. object as? NSManagedObjectContext
380
+ guard context? . name == backgroundContextName else {
381
+ return
382
+ }
383
+
376
384
if Thread . isMainThread && TestCheck . isTesting == false {
377
385
throw NSError ( info: " Background context saved in the main thread. Use context's `performBlock` " , previousError: nil )
378
386
} else {
You can’t perform that action at this time.
0 commit comments