From f85eb2e057df730c0fa7ef8934b81f513edf14a7 Mon Sep 17 00:00:00 2001 From: John Rommel Estropia Date: Fri, 24 Jul 2015 08:05:13 +0900 Subject: [PATCH] merge changes to the main context asynchronously (fixes https://github.com/JohnEstropia/CoreStore/issues/7) --- CoreStore.podspec | 2 +- CoreStore/Info.plist | 2 +- .../NSManagedObjectContext+Setup.swift | 3 +-- .../AsynchronousDataTransaction.swift | 22 ++----------------- 4 files changed, 5 insertions(+), 24 deletions(-) diff --git a/CoreStore.podspec b/CoreStore.podspec index 70e6ebd..c21c209 100644 --- a/CoreStore.podspec +++ b/CoreStore.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "CoreStore" - s.version = "1.0.0" + s.version = "1.0.1" s.license = "MIT" s.summary = "Simple, elegant, and smart Core Data programming with Swift" s.homepage = "https://github.com/JohnEstropia/CoreStore" diff --git a/CoreStore/Info.plist b/CoreStore/Info.plist index 60b9c00..7a84553 100644 --- a/CoreStore/Info.plist +++ b/CoreStore/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.0.0 + 1.0.1 CFBundleSignature ???? CFBundleVersion diff --git a/CoreStore/Internal/NSManagedObjectContext+Setup.swift b/CoreStore/Internal/NSManagedObjectContext+Setup.swift index 214fcc1..875285b 100644 --- a/CoreStore/Internal/NSManagedObjectContext+Setup.swift +++ b/CoreStore/Internal/NSManagedObjectContext+Setup.swift @@ -83,11 +83,10 @@ internal extension NSManagedObjectContext { object: rootContext, closure: { [weak context] (note) -> Void in - context?.performBlockAndWait { () -> Void in + context?.performBlock { () -> Void in context?.mergeChangesFromContextDidSaveNotification(note) } - return } ) diff --git a/CoreStore/Saving and Processing/AsynchronousDataTransaction.swift b/CoreStore/Saving and Processing/AsynchronousDataTransaction.swift index 144faf6..66b13cb 100644 --- a/CoreStore/Saving and Processing/AsynchronousDataTransaction.swift +++ b/CoreStore/Saving and Processing/AsynchronousDataTransaction.swift @@ -38,11 +38,11 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { // 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. */ - public func commit(completion: (result: SaveResult) -> Void) { + public func commit(completion: (result: SaveResult) -> Void = { _ in }) { CoreStore.assert( self.transactionQueue.isCurrentExecutionContext(), @@ -64,24 +64,6 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { 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.