From a55a8d389c4ae340e279c92e63f805e4182b2e43 Mon Sep 17 00:00:00 2001 From: Mamad Purbo Date: Mon, 22 Feb 2016 11:50:28 +0900 Subject: [PATCH 1/4] added missing closing bracket on sample code. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 81925b6..3737846 100644 --- a/README.md +++ b/README.md @@ -260,9 +260,9 @@ do { completion: { (result) -> Void in switch result { case .Success(let persistentStore): - print("Successfully added sqlite store: \(persistentStore)" + print("Successfully added sqlite store: \(persistentStore)") case .Failure(let error): - print("Failed adding sqlite store with error: \(error)" + print("Failed adding sqlite store with error: \(error)") } } ) From 15353268e28d4946b2e002ee33af2f7a55d5be48 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Thu, 25 Feb 2016 15:04:05 +0900 Subject: [PATCH 2/4] Allow unsafe transactions to save synchronously --- CoreStore.podspec | 2 +- CoreStore/Info.plist | 2 +- .../SynchronousDataTransaction.swift | 11 ++++++++++- .../Saving and Processing/UnsafeDataTransaction.swift | 11 +++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CoreStore.podspec b/CoreStore.podspec index 989b6f6..563275f 100644 --- a/CoreStore.podspec +++ b/CoreStore.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "CoreStore" - s.version = "1.5.1" + s.version = "1.5.2" s.license = "MIT" s.summary = "Unleashing the real power of Core Data with the elegance and safety of Swift" s.homepage = "https://github.com/JohnEstropia/CoreStore" diff --git a/CoreStore/Info.plist b/CoreStore/Info.plist index d18bd0a..c1add73 100644 --- a/CoreStore/Info.plist +++ b/CoreStore/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.5.1 + 1.5.2 CFBundleSignature ???? CFBundleVersion diff --git a/CoreStore/Saving and Processing/SynchronousDataTransaction.swift b/CoreStore/Saving and Processing/SynchronousDataTransaction.swift index cb11bf3..9519913 100644 --- a/CoreStore/Saving and Processing/SynchronousDataTransaction.swift +++ b/CoreStore/Saving and Processing/SynchronousDataTransaction.swift @@ -39,8 +39,10 @@ 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. + + - returns: a `SaveResult` containing the success or failure information */ - public func commit() { + public func commitAndWait() -> SaveResult { CoreStore.assert( self.transactionQueue.isCurrentExecutionContext(), @@ -53,6 +55,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction { self.isCommitted = true self.result = self.context.saveSynchronously() + return self.result } /** @@ -197,6 +200,12 @@ public final class SynchronousDataTransaction: BaseDataTransaction { self.context.reset() } + @available(*, deprecated=1.5.2, renamed="commitAndWait") + public func commit() { + + self.commitAndWait() + } + // MARK: Internal diff --git a/CoreStore/Saving and Processing/UnsafeDataTransaction.swift b/CoreStore/Saving and Processing/UnsafeDataTransaction.swift index 74aaafe..ae70fb0 100644 --- a/CoreStore/Saving and Processing/UnsafeDataTransaction.swift +++ b/CoreStore/Saving and Processing/UnsafeDataTransaction.swift @@ -55,6 +55,17 @@ public final class UnsafeDataTransaction: BaseDataTransaction { } } + /** + Saves the transaction changes and waits for completion synchronously. For a `UnsafeDataTransaction`, multiple commits are allowed, although it is the developer's responsibility to ensure a reasonable leeway to prevent blocking the main thread. + + - returns: a `SaveResult` containing the success or failure information + */ + public func commitAndWait() -> SaveResult { + + self.result = self.context.saveSynchronously() + return self.result + } + /** Rolls back the transaction. */ From 39054230380c3da4d5cd44d4315a9a3c54eb14fc Mon Sep 17 00:00:00 2001 From: John Estropia Date: Thu, 25 Feb 2016 15:05:27 +0900 Subject: [PATCH 3/4] fix compile error --- .../Saving and Processing/SynchronousDataTransaction.swift | 6 ++++-- CoreStore/Saving and Processing/UnsafeDataTransaction.swift | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CoreStore/Saving and Processing/SynchronousDataTransaction.swift b/CoreStore/Saving and Processing/SynchronousDataTransaction.swift index 9519913..1b43ac9 100644 --- a/CoreStore/Saving and Processing/SynchronousDataTransaction.swift +++ b/CoreStore/Saving and Processing/SynchronousDataTransaction.swift @@ -54,8 +54,10 @@ public final class SynchronousDataTransaction: BaseDataTransaction { ) self.isCommitted = true - self.result = self.context.saveSynchronously() - return self.result + + let result = self.context.saveSynchronously() + self.result = result + return result } /** diff --git a/CoreStore/Saving and Processing/UnsafeDataTransaction.swift b/CoreStore/Saving and Processing/UnsafeDataTransaction.swift index ae70fb0..0ef1b94 100644 --- a/CoreStore/Saving and Processing/UnsafeDataTransaction.swift +++ b/CoreStore/Saving and Processing/UnsafeDataTransaction.swift @@ -62,8 +62,9 @@ public final class UnsafeDataTransaction: BaseDataTransaction { */ public func commitAndWait() -> SaveResult { - self.result = self.context.saveSynchronously() - return self.result + let result = self.context.saveSynchronously() + self.result = result + return result } /** From 4c78a309bc0ae56bf22f1249b6027fb202470715 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Thu, 25 Feb 2016 15:52:49 +0900 Subject: [PATCH 4/4] deprecated NSFetchedResultsController initializer in favor of static factory method --- CoreStore.podspec | 2 +- ...FetchedResultsController+Convenience.swift | 35 +++++++++++++++++-- CoreStore/Info.plist | 2 +- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/CoreStore.podspec b/CoreStore.podspec index 563275f..2b4365b 100644 --- a/CoreStore.podspec +++ b/CoreStore.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "CoreStore" - s.version = "1.5.2" + s.version = "1.5.3" s.license = "MIT" s.summary = "Unleashing the real power of Core Data with the elegance and safety of Swift" s.homepage = "https://github.com/JohnEstropia/CoreStore" diff --git a/CoreStore/Convenience Helpers/NSFetchedResultsController+Convenience.swift b/CoreStore/Convenience Helpers/NSFetchedResultsController+Convenience.swift index ef0d0d6..6dd1452 100644 --- a/CoreStore/Convenience Helpers/NSFetchedResultsController+Convenience.swift +++ b/CoreStore/Convenience Helpers/NSFetchedResultsController+Convenience.swift @@ -34,7 +34,7 @@ public extension NSFetchedResultsController { /** Utility for creating an `NSFetchedResultsController` from a `DataStack`. This is useful to partially support Objective-C classes by passing an `NSFetchedResultsController` instance instead of a `ListMonitor`. */ - public func createForStack(dataStack: DataStack, fetchRequest: NSFetchRequest, from: From? = nil, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) -> NSFetchedResultsController { + public static func createForStack(dataStack: DataStack, fetchRequest: NSFetchRequest, from: From? = nil, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) -> NSFetchedResultsController { return CoreStoreFetchedResultsController( context: dataStack.mainContext, @@ -45,10 +45,41 @@ public extension NSFetchedResultsController { ) } + @available(*, deprecated=1.5.2, message="Use NSFetchedResultsController.createForStack(_:fetchRequest:from:sectionBy:fetchClauses:) to create NSFetchedResultsControllers directly") + public convenience init(dataStack: DataStack, fetchRequest: NSFetchRequest, from: From? = nil, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) { + + let context = dataStack.mainContext + from?.applyToFetchRequest(fetchRequest, context: context, applyAffectedStores: false) + for clause in fetchClauses { + + clause.applyToFetchRequest(fetchRequest) + } + + if let from = from { + + from.applyAffectedStoresForFetchedRequest(fetchRequest, context: context) + } + else { + + guard let from = (fetchRequest.entity.flatMap { $0.managedObjectClassName }).flatMap(NSClassFromString).flatMap(From.init) else { + + fatalError("Attempted to create an \(typeName(NSFetchedResultsController)) without a From clause or an NSEntityDescription.") + } + from.applyAffectedStoresForFetchedRequest(fetchRequest, context: context) + } + + self.init( + fetchRequest: fetchRequest, + managedObjectContext: context, + sectionNameKeyPath: sectionBy?.sectionKeyPath, + cacheName: nil + ) + } + // MARK: Internal - internal func createFromContext(context: NSManagedObjectContext, fetchRequest: NSFetchRequest, from: From? = nil, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) -> NSFetchedResultsController { + internal static func createFromContext(context: NSManagedObjectContext, fetchRequest: NSFetchRequest, from: From? = nil, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) -> NSFetchedResultsController { return CoreStoreFetchedResultsController( context: context, diff --git a/CoreStore/Info.plist b/CoreStore/Info.plist index c1add73..77238c6 100644 --- a/CoreStore/Info.plist +++ b/CoreStore/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.5.2 + 1.5.3 CFBundleSignature ???? CFBundleVersion