diff --git a/Carthage/Checkouts/GCDKit b/Carthage/Checkouts/GCDKit index 822fe55..90d4f31 160000 --- a/Carthage/Checkouts/GCDKit +++ b/Carthage/Checkouts/GCDKit @@ -1 +1 @@ -Subproject commit 822fe55fc49fb39d6f9cf97b2f9c048fc6a74179 +Subproject commit 90d4f31f63a1c98bf7090381c844c62d73a4c8eb diff --git a/CoreStore.podspec b/CoreStore.podspec index 918d6f8..95bd8b6 100644 --- a/CoreStore.podspec +++ b/CoreStore.podspec @@ -18,5 +18,5 @@ Pod::Spec.new do |s| s.requires_arc = true s.pod_target_xcconfig = { 'OTHER_SWIFT_FLAGS' => '-D USE_FRAMEWORKS' } - s.dependency "GCDKit", "1.2.4" + s.dependency "GCDKit", "1.2.5" end \ No newline at end of file diff --git a/README.md b/README.md index 91bee3d..4190ab2 100644 --- a/README.md +++ b/README.md @@ -729,7 +729,7 @@ or multiple objects at once with the `importUniqueObjects(...)` method: ```swift CoreStore.beginAsynchronous { (transaction) -> Void in let jsonArray: [[String: AnyObject]] = // ... - try! transaction.importObjects( + try! transaction.importUniqueObjects( Into(MyPersonEntity), sourceArray: jsonArray ) diff --git a/Sources/Transactions/UnsafeDataTransaction.swift b/Sources/Transactions/UnsafeDataTransaction.swift index 54bae12..cd34b5b 100644 --- a/Sources/Transactions/UnsafeDataTransaction.swift +++ b/Sources/Transactions/UnsafeDataTransaction.swift @@ -87,6 +87,30 @@ public final class UnsafeDataTransaction: BaseDataTransaction { self.context.undo() } + /** + Immediately flushes all pending changes to the transaction's observers. This is useful in conjunction with `ListMonitor`s and `ObjectMonitor`s created from `UnsafeDataTransaction`s used to manage temporary "scratch" data. + + - Important: Note that unlike `commit()`, `flush()` does not propagate/save updates to the `DataStack` and the persistent store. However, the flushed changes will be seen by children transactions created further from the current transaction (i.e. through `transaction.beginUnsafe()`) + - throws: an error thrown from `closure`, or an error thrown by Core Data (usually validation errors or conflict errors) + */ + public func flush() throws { + + try self.context.save() + } + + /** + Flushes all pending changes to the transaction's observers at the end of the `closure`'s execution. This is useful in conjunction with `ListMonitor`s and `ObjectMonitor`s created from `UnsafeDataTransaction`s used to manage temporary "scratch" data. + + - Important: Note that unlike `commit()`, `flush()` does not propagate/save updates to the `DataStack` and the persistent store. However, the flushed changes will be seen by children transactions created further from the current transaction (i.e. through `transaction.beginUnsafe()`) + - parameter closure: the closure where changes can be made prior to the flush + - throws: an error thrown from `closure`, or an error thrown by Core Data (usually validation errors or conflict errors) + */ + public func flush(@noescape closure: () throws -> Void) throws { + + try closure() + try self.context.save() + } + /** Redo's the last undone change to the transaction. */ @@ -118,7 +142,7 @@ public final class UnsafeDataTransaction: BaseDataTransaction { /** Returns the `NSManagedObjectContext` for this unsafe transaction. Use only for cases where external frameworks need an `NSManagedObjectContext` instance to work with. - - Note: It is the developer's responsibility to ensure the following: + - Important: It is the developer's responsibility to ensure the following: - that the `UnsafeDataTransaction` that owns this context should be strongly referenced and prevented from being deallocated during the context's lifetime - that all saves will be done either through the `UnsafeDataTransaction`'s `commit(...)` method, or by calling `save()` manually on the context, its parent, and all other ancestor contexts if there are any. */