mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-24 18:31:41 +01:00
remove queue asserts for detached transactions
This commit is contained in:
@@ -332,11 +332,11 @@
|
|||||||
B56007101B3F6BD500A9A8F9 /* Into.swift */,
|
B56007101B3F6BD500A9A8F9 /* Into.swift */,
|
||||||
B5E84EEB1AFF846E0064E85B /* BaseDataTransaction.swift */,
|
B5E84EEB1AFF846E0064E85B /* BaseDataTransaction.swift */,
|
||||||
B5E84EEA1AFF846E0064E85B /* AsynchronousDataTransaction.swift */,
|
B5E84EEA1AFF846E0064E85B /* AsynchronousDataTransaction.swift */,
|
||||||
B5E84EEC1AFF846E0064E85B /* DataStack+Transaction.swift */,
|
B5E84EF31AFF846E0064E85B /* SynchronousDataTransaction.swift */,
|
||||||
B5E84EED1AFF846E0064E85B /* DetachedDataTransaction.swift */,
|
B5E84EED1AFF846E0064E85B /* DetachedDataTransaction.swift */,
|
||||||
|
B5E84EEC1AFF846E0064E85B /* DataStack+Transaction.swift */,
|
||||||
B5E84EEE1AFF846E0064E85B /* CoreStore+Transaction.swift */,
|
B5E84EEE1AFF846E0064E85B /* CoreStore+Transaction.swift */,
|
||||||
B5E84EF21AFF846E0064E85B /* SaveResult.swift */,
|
B5E84EF21AFF846E0064E85B /* SaveResult.swift */,
|
||||||
B5E84EF31AFF846E0064E85B /* SynchronousDataTransaction.swift */,
|
|
||||||
);
|
);
|
||||||
path = "Saving and Processing";
|
path = "Saving and Processing";
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
|||||||
@@ -75,7 +75,6 @@ internal extension NSManagedObjectContext {
|
|||||||
let context = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType)
|
let context = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType)
|
||||||
context.parentContext = rootContext
|
context.parentContext = rootContext
|
||||||
context.mergePolicy = NSRollbackMergePolicy
|
context.mergePolicy = NSRollbackMergePolicy
|
||||||
context.shouldCascadeSavesToParent = false
|
|
||||||
context.undoManager = nil
|
context.undoManager = nil
|
||||||
context.setupForCoreStoreWithContextName("com.corestore.maincontext")
|
context.setupForCoreStoreWithContextName("com.corestore.maincontext")
|
||||||
context.observerForDidSaveNotification = NotificationObserver(
|
context.observerForDidSaveNotification = NotificationObserver(
|
||||||
|
|||||||
@@ -150,14 +150,7 @@ internal extension NSManagedObjectContext {
|
|||||||
|
|
||||||
if let parentContext = self.parentContext where self.shouldCascadeSavesToParent {
|
if let parentContext = self.parentContext where self.shouldCascadeSavesToParent {
|
||||||
|
|
||||||
let result = parentContext.saveSynchronously()
|
parentContext.saveAsynchronouslyWithCompletion(completion)
|
||||||
if let completion = completion {
|
|
||||||
|
|
||||||
GCDQueue.Main.async {
|
|
||||||
|
|
||||||
completion(result: result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if let completion = completion {
|
else if let completion = completion {
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public /*abstract*/ class BaseDataTransaction {
|
|||||||
public func create<T: NSManagedObject>(into: Into<T>) -> T {
|
public func create<T: NSManagedObject>(into: Into<T>) -> T {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.transactionQueue.isCurrentExecutionContext(),
|
self.bypassesQueueing || self.transactionQueue.isCurrentExecutionContext(),
|
||||||
"Attempted to create an entity of type \(typeName(T)) outside its designated queue."
|
"Attempted to create an entity of type \(typeName(T)) outside its designated queue."
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@ public /*abstract*/ class BaseDataTransaction {
|
|||||||
public func edit<T: NSManagedObject>(object: T?) -> T? {
|
public func edit<T: NSManagedObject>(object: T?) -> T? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.transactionQueue.isCurrentExecutionContext(),
|
self.bypassesQueueing || self.transactionQueue.isCurrentExecutionContext(),
|
||||||
"Attempted to update an entity of type \(typeName(object)) outside its designated queue."
|
"Attempted to update an entity of type \(typeName(object)) outside its designated queue."
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -124,7 +124,7 @@ public /*abstract*/ class BaseDataTransaction {
|
|||||||
public func edit<T: NSManagedObject>(into: Into<T>, _ objectID: NSManagedObjectID) -> T? {
|
public func edit<T: NSManagedObject>(into: Into<T>, _ objectID: NSManagedObjectID) -> T? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.transactionQueue.isCurrentExecutionContext(),
|
self.bypassesQueueing || self.transactionQueue.isCurrentExecutionContext(),
|
||||||
"Attempted to update an entity of type \(typeName(T)) outside its designated queue."
|
"Attempted to update an entity of type \(typeName(T)) outside its designated queue."
|
||||||
)
|
)
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
@@ -144,7 +144,7 @@ public /*abstract*/ class BaseDataTransaction {
|
|||||||
public func delete(object: NSManagedObject?) {
|
public func delete(object: NSManagedObject?) {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.transactionQueue.isCurrentExecutionContext(),
|
self.bypassesQueueing || self.transactionQueue.isCurrentExecutionContext(),
|
||||||
"Attempted to delete an entity outside its designated queue."
|
"Attempted to delete an entity outside its designated queue."
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -171,7 +171,7 @@ public /*abstract*/ class BaseDataTransaction {
|
|||||||
public func delete(objects: [NSManagedObject?]) {
|
public func delete(objects: [NSManagedObject?]) {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.transactionQueue.isCurrentExecutionContext(),
|
self.bypassesQueueing || self.transactionQueue.isCurrentExecutionContext(),
|
||||||
"Attempted to delete entities outside their designated queue."
|
"Attempted to delete entities outside their designated queue."
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -190,7 +190,7 @@ public /*abstract*/ class BaseDataTransaction {
|
|||||||
public func rollback() {
|
public func rollback() {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.transactionQueue.isCurrentExecutionContext(),
|
self.bypassesQueueing || self.transactionQueue.isCurrentExecutionContext(),
|
||||||
"Attempted to rollback a \(typeName(self)) outside its designated queue."
|
"Attempted to rollback a \(typeName(self)) outside its designated queue."
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -220,4 +220,9 @@ public /*abstract*/ class BaseDataTransaction {
|
|||||||
|
|
||||||
context.parentTransaction = self
|
context.parentTransaction = self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal var bypassesQueueing: Bool {
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,16 +43,19 @@ public final class DetachedDataTransaction: BaseDataTransaction {
|
|||||||
*/
|
*/
|
||||||
public func commit(completion: (result: SaveResult) -> Void) {
|
public func commit(completion: (result: SaveResult) -> Void) {
|
||||||
|
|
||||||
CoreStore.assert(
|
|
||||||
self.transactionQueue.isCurrentExecutionContext(),
|
|
||||||
"Attempted to commit a \(typeName(self)) outside its designated queue."
|
|
||||||
)
|
|
||||||
|
|
||||||
self.context.saveAsynchronouslyWithCompletion { (result) -> Void in
|
self.context.saveAsynchronouslyWithCompletion { (result) -> Void in
|
||||||
|
|
||||||
self.result = result
|
self.result = result
|
||||||
completion(result: result)
|
completion(result: result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// MARK: Internal
|
||||||
|
|
||||||
|
internal override var bypassesQueueing: Bool {
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user