mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-21 17:09:42 +01:00
merge changes to the main context asynchronously (fixes https://github.com/JohnEstropia/CoreStore/issues/7)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
Pod::Spec.new do |s|
|
Pod::Spec.new do |s|
|
||||||
s.name = "CoreStore"
|
s.name = "CoreStore"
|
||||||
s.version = "1.0.0"
|
s.version = "1.0.1"
|
||||||
s.license = "MIT"
|
s.license = "MIT"
|
||||||
s.summary = "Simple, elegant, and smart Core Data programming with Swift"
|
s.summary = "Simple, elegant, and smart Core Data programming with Swift"
|
||||||
s.homepage = "https://github.com/JohnEstropia/CoreStore"
|
s.homepage = "https://github.com/JohnEstropia/CoreStore"
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
<string>FMWK</string>
|
<string>FMWK</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>1.0.0</string>
|
<string>1.0.1</string>
|
||||||
<key>CFBundleSignature</key>
|
<key>CFBundleSignature</key>
|
||||||
<string>????</string>
|
<string>????</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
|
|||||||
@@ -83,11 +83,10 @@ internal extension NSManagedObjectContext {
|
|||||||
object: rootContext,
|
object: rootContext,
|
||||||
closure: { [weak context] (note) -> Void in
|
closure: { [weak context] (note) -> Void in
|
||||||
|
|
||||||
context?.performBlockAndWait { () -> Void in
|
context?.performBlock { () -> Void in
|
||||||
|
|
||||||
context?.mergeChangesFromContextDidSaveNotification(note)
|
context?.mergeChangesFromContextDidSaveNotification(note)
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -38,11 +38,11 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
|||||||
// MARK: Public
|
// MARK: Public
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Saves the transaction changes asynchronously. This method should not be used after the `commit()` method was already called once.
|
Saves the transaction changes. This method should not be used after the `commit()` method was already called once.
|
||||||
|
|
||||||
- parameter completion: the block executed after the save completes. Success or failure is reported by the `SaveResult` argument of the block.
|
- parameter completion: the block executed after the save completes. Success or failure is reported by the `SaveResult` argument of the block.
|
||||||
*/
|
*/
|
||||||
public func commit(completion: (result: SaveResult) -> Void) {
|
public func commit(completion: (result: SaveResult) -> Void = { _ in }) {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.transactionQueue.isCurrentExecutionContext(),
|
self.transactionQueue.isCurrentExecutionContext(),
|
||||||
@@ -64,24 +64,6 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
|||||||
semaphore.wait()
|
semaphore.wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Saves the transaction changes and waits for completion synchronously. This method should not be used after the `commit()` method was already called once.
|
|
||||||
*/
|
|
||||||
public func commit() {
|
|
||||||
|
|
||||||
CoreStore.assert(
|
|
||||||
self.transactionQueue.isCurrentExecutionContext(),
|
|
||||||
"Attempted to commit a \(typeName(self)) outside its designated queue."
|
|
||||||
)
|
|
||||||
CoreStore.assert(
|
|
||||||
!self.isCommitted,
|
|
||||||
"Attempted to commit a \(typeName(self)) more than once."
|
|
||||||
)
|
|
||||||
|
|
||||||
self.isCommitted = true
|
|
||||||
self.result = self.context.saveSynchronously()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Begins a child transaction synchronously where NSManagedObject creates, updates, and deletes can be made. This method should not be used after the `commit()` method was already called once.
|
Begins a child transaction synchronously where NSManagedObject creates, updates, and deletes can be made. This method should not be used after the `commit()` method was already called once.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user