version bump, cleanup, unit test

This commit is contained in:
John Estropia
2016-09-30 13:28:19 +09:00
parent 243b6a76d5
commit 862ef27374
12 changed files with 151 additions and 44 deletions

View File

@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.1.1</string>
<string>2.1.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>

View File

@@ -101,7 +101,7 @@ internal extension NSManagedObjectContext {
}
@nonobjc
internal func saveSynchronously(mergeSynchronously: Bool = true) -> SaveResult {
internal func saveSynchronously(waitForMerge waitForMerge: Bool) -> SaveResult {
var result = SaveResult(hasChanges: false)
@@ -114,7 +114,7 @@ internal extension NSManagedObjectContext {
do {
self.isSavingSynchronously = mergeSynchronously
self.isSavingSynchronously = waitForMerge
try self.save()
self.isSavingSynchronously = nil
}
@@ -131,7 +131,7 @@ internal extension NSManagedObjectContext {
if let parentContext = self.parentContext where self.shouldCascadeSavesToParent {
switch parentContext.saveSynchronously(mergeSynchronously) {
switch parentContext.saveSynchronously(waitForMerge: waitForMerge) {
case .Success:
result = SaveResult(hasChanges: true)

View File

@@ -38,7 +38,8 @@ import CoreData
public final class SynchronousDataTransaction: BaseDataTransaction {
/**
Saves the transaction changes and waits for completion synchronously. This method should not be used after the `commit()` method was already called once.
Saves the transaction changes and waits for completion synchronously. This method should not be used after the `commit()` or `commitAndWait()` method was already called once.
- Important: Unlike `SynchronousDataTransaction.commit()`, this method waits for all observers to be notified of the changes before returning. This results in more predictable data update order, but may risk triggering deadlocks.
- returns: a `SaveResult` containing the success or failure information
*/
@@ -55,35 +56,33 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
self.isCommitted = true
let result = self.context.saveSynchronously()
let result = self.context.saveSynchronously(waitForMerge: true)
self.result = result
return result
}
/**
Saves the transaction changes and waits for completion synchronously, but merges into the main context asynchronously. This method should not be used after the `commit()` method was already called once.
This method can be used to avoid potential deadlocks that can arise when a background thread attempts to merge changes into the main context while the main queue is querying from that context. Note that this
introduces a possibility that the main thread can attempt to query for the changes before the asynchronous merge operation has happened.
Saves the transaction changes and waits for completion synchronously. This method should not be used after the `commit()` or `commitAndWait()` method was already called once.
- Important: Unlike `SynchronousDataTransaction.commitAndWait()`, this method does not wait for observers to be notified of the changes before returning. This results in lower risk for deadlocks, but the updated data may not have been propagated to the `DataStack` after returning.
- returns: a `SaveResult` containing the success or failure information
*/
public func commit() -> SaveResult {
CoreStore.assert(
self.transactionQueue.isCurrentExecutionContext(),
"Attempted to commit a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.isCommitted,
"Attempted to commit a \(cs_typeName(self)) more than once."
)
self.isCommitted = true
let result = self.context.saveSynchronously(false)
self.result = result
return result
CoreStore.assert(
self.transactionQueue.isCurrentExecutionContext(),
"Attempted to commit a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.isCommitted,
"Attempted to commit a \(cs_typeName(self)) more than once."
)
self.isCommitted = true
let result = self.context.saveSynchronously(waitForMerge: false)
self.result = result
return result
}
/**

View File

@@ -58,7 +58,7 @@ public final class UnsafeDataTransaction: BaseDataTransaction {
*/
public func commitAndWait() -> SaveResult {
let result = self.context.saveSynchronously()
let result = self.context.saveSynchronously(waitForMerge: true)
self.result = result
return result
}