From 4c78a309bc0ae56bf22f1249b6027fb202470715 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Thu, 25 Feb 2016 15:52:49 +0900 Subject: [PATCH] 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