mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-27 20:01:27 +01:00
added a convenience initializer for clients that only support NSFetchedResultsController (i.e. Objective-C)
This commit is contained in:
@@ -12,7 +12,7 @@ Pod::Spec.new do |s|
|
|||||||
s.watchos.deployment_target = "2.0"
|
s.watchos.deployment_target = "2.0"
|
||||||
|
|
||||||
s.source_files = "CoreStore", "CoreStore/**/*.{swift}"
|
s.source_files = "CoreStore", "CoreStore/**/*.{swift}"
|
||||||
s.osx.exclude_files = "CoreStore/Observing/*.{swift}", "CoreStore/Internal/FetchedResultsControllerDelegate.swift"
|
s.osx.exclude_files = "CoreStore/Observing/*.{swift}", "CoreStore/Internal/FetchedResultsControllerDelegate.swift", "CoreStore/Internal/NSFetchedResultsController+Convenience.swift"
|
||||||
s.frameworks = "Foundation", "CoreData"
|
s.frameworks = "Foundation", "CoreData"
|
||||||
s.requires_arc = true
|
s.requires_arc = true
|
||||||
s.pod_target_xcconfig = { 'OTHER_SWIFT_FLAGS' => '-D USE_FRAMEWORKS' }
|
s.pod_target_xcconfig = { 'OTHER_SWIFT_FLAGS' => '-D USE_FRAMEWORKS' }
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
2F291E2719C6D3CF007AF63F /* CoreStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F291E2619C6D3CF007AF63F /* CoreStore.swift */; };
|
2F291E2719C6D3CF007AF63F /* CoreStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F291E2619C6D3CF007AF63F /* CoreStore.swift */; };
|
||||||
B504D0D61B02362500B2BBB1 /* CoreStore+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B504D0D51B02362500B2BBB1 /* CoreStore+Setup.swift */; };
|
B504D0D61B02362500B2BBB1 /* CoreStore+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B504D0D51B02362500B2BBB1 /* CoreStore+Setup.swift */; };
|
||||||
B51BE06A1B47FC4B0069F532 /* NSManagedObjectModel+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51BE0691B47FC4B0069F532 /* NSManagedObjectModel+Setup.swift */; };
|
B51BE06A1B47FC4B0069F532 /* NSManagedObjectModel+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51BE0691B47FC4B0069F532 /* NSManagedObjectModel+Setup.swift */; };
|
||||||
|
B5202CFA1C04688100DED140 /* NSFetchedResultsController+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5202CF91C04688100DED140 /* NSFetchedResultsController+Convenience.swift */; };
|
||||||
|
B5202CFD1C046E8400DED140 /* NSFetchedResultsController+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5202CF91C04688100DED140 /* NSFetchedResultsController+Convenience.swift */; };
|
||||||
B52DD17E1BE1F8CD00949AFE /* CoreStore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B52DD1741BE1F8CC00949AFE /* CoreStore.framework */; };
|
B52DD17E1BE1F8CD00949AFE /* CoreStore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B52DD1741BE1F8CC00949AFE /* CoreStore.framework */; };
|
||||||
B52DD1901BE1F8E600949AFE /* GCDKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5D808021A34715700A44484 /* GCDKit.framework */; };
|
B52DD1901BE1F8E600949AFE /* GCDKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5D808021A34715700A44484 /* GCDKit.framework */; };
|
||||||
B52DD1911BE1F8EB00949AFE /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5548CD51BD65AE00077652A /* Foundation.framework */; };
|
B52DD1911BE1F8EB00949AFE /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5548CD51BD65AE00077652A /* Foundation.framework */; };
|
||||||
@@ -274,6 +276,7 @@
|
|||||||
2F291E2619C6D3CF007AF63F /* CoreStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = CoreStore.swift; sourceTree = "<group>"; };
|
2F291E2619C6D3CF007AF63F /* CoreStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = CoreStore.swift; sourceTree = "<group>"; };
|
||||||
B504D0D51B02362500B2BBB1 /* CoreStore+Setup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CoreStore+Setup.swift"; sourceTree = "<group>"; };
|
B504D0D51B02362500B2BBB1 /* CoreStore+Setup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CoreStore+Setup.swift"; sourceTree = "<group>"; };
|
||||||
B51BE0691B47FC4B0069F532 /* NSManagedObjectModel+Setup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSManagedObjectModel+Setup.swift"; sourceTree = "<group>"; };
|
B51BE0691B47FC4B0069F532 /* NSManagedObjectModel+Setup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSManagedObjectModel+Setup.swift"; sourceTree = "<group>"; };
|
||||||
|
B5202CF91C04688100DED140 /* NSFetchedResultsController+Convenience.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSFetchedResultsController+Convenience.swift"; sourceTree = "<group>"; };
|
||||||
B52DD1741BE1F8CC00949AFE /* CoreStore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CoreStore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
B52DD1741BE1F8CC00949AFE /* CoreStore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CoreStore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
B52DD17D1BE1F8CC00949AFE /* CoreStoreTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CoreStoreTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
B52DD17D1BE1F8CC00949AFE /* CoreStoreTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CoreStoreTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
B54A6A541BA15F2A007870FD /* FetchedResultsControllerDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchedResultsControllerDelegate.swift; sourceTree = "<group>"; };
|
B54A6A541BA15F2A007870FD /* FetchedResultsControllerDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchedResultsControllerDelegate.swift; sourceTree = "<group>"; };
|
||||||
@@ -617,6 +620,7 @@
|
|||||||
children = (
|
children = (
|
||||||
B5E84F271AFF84920064E85B /* NSManagedObject+Convenience.swift */,
|
B5E84F271AFF84920064E85B /* NSManagedObject+Convenience.swift */,
|
||||||
B5FAD6A81B50A4B300714891 /* NSProgress+Convenience.swift */,
|
B5FAD6A81B50A4B300714891 /* NSProgress+Convenience.swift */,
|
||||||
|
B5202CF91C04688100DED140 /* NSFetchedResultsController+Convenience.swift */,
|
||||||
);
|
);
|
||||||
path = "Convenience Helpers";
|
path = "Convenience Helpers";
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -918,6 +922,7 @@
|
|||||||
B5E84EE71AFF84610064E85B /* CoreStore+Logging.swift in Sources */,
|
B5E84EE71AFF84610064E85B /* CoreStore+Logging.swift in Sources */,
|
||||||
B56007111B3F6BD500A9A8F9 /* Into.swift in Sources */,
|
B56007111B3F6BD500A9A8F9 /* Into.swift in Sources */,
|
||||||
B5E84F111AFF847B0064E85B /* Select.swift in Sources */,
|
B5E84F111AFF847B0064E85B /* Select.swift in Sources */,
|
||||||
|
B5202CFA1C04688100DED140 /* NSFetchedResultsController+Convenience.swift in Sources */,
|
||||||
B5E84EE11AFF84500064E85B /* PersistentStoreResult.swift in Sources */,
|
B5E84EE11AFF84500064E85B /* PersistentStoreResult.swift in Sources */,
|
||||||
B5E84F251AFF84860064E85B /* ObjectObserver.swift in Sources */,
|
B5E84F251AFF84860064E85B /* ObjectObserver.swift in Sources */,
|
||||||
B5E84F2F1AFF849C0064E85B /* NotificationObserver.swift in Sources */,
|
B5E84F2F1AFF849C0064E85B /* NotificationObserver.swift in Sources */,
|
||||||
@@ -1056,6 +1061,7 @@
|
|||||||
B56321811BD65216006C9394 /* DataStack.swift in Sources */,
|
B56321811BD65216006C9394 /* DataStack.swift in Sources */,
|
||||||
B56321A81BD65219006C9394 /* NSManagedObject+Convenience.swift in Sources */,
|
B56321A81BD65219006C9394 /* NSManagedObject+Convenience.swift in Sources */,
|
||||||
B56321981BD65216006C9394 /* Where.swift in Sources */,
|
B56321981BD65216006C9394 /* Where.swift in Sources */,
|
||||||
|
B5202CFD1C046E8400DED140 /* NSFetchedResultsController+Convenience.swift in Sources */,
|
||||||
B56321AF1BD6521C006C9394 /* NSFileManager+Setup.swift in Sources */,
|
B56321AF1BD6521C006C9394 /* NSFileManager+Setup.swift in Sources */,
|
||||||
B56321971BD65216006C9394 /* Select.swift in Sources */,
|
B56321971BD65216006C9394 /* Select.swift in Sources */,
|
||||||
B56321AB1BD6521C006C9394 /* FetchedResultsControllerDelegate.swift in Sources */,
|
B56321AB1BD6521C006C9394 /* FetchedResultsControllerDelegate.swift in Sources */,
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
//
|
||||||
|
// NSManagedObject+Convenience.swift
|
||||||
|
// CoreStore
|
||||||
|
//
|
||||||
|
// Copyright (c) 2015 John Rommel Estropia
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import CoreData
|
||||||
|
|
||||||
|
|
||||||
|
// MARK: - NSFetchedResultsController
|
||||||
|
|
||||||
|
public extension NSFetchedResultsController {
|
||||||
|
|
||||||
|
public convenience init<T: NSManagedObject>(dataStack: DataStack, fetchRequest: NSFetchRequest, from: From<T>? = nil, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) {
|
||||||
|
|
||||||
|
let context = dataStack.mainContext
|
||||||
|
from?.applyToFetchRequest(fetchRequest, context: context)
|
||||||
|
for clause in fetchClauses {
|
||||||
|
|
||||||
|
clause.applyToFetchRequest(fetchRequest)
|
||||||
|
}
|
||||||
|
|
||||||
|
self.init(
|
||||||
|
fetchRequest: fetchRequest,
|
||||||
|
managedObjectContext: context,
|
||||||
|
sectionNameKeyPath: sectionBy?.sectionKeyPath,
|
||||||
|
cacheName: nil
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -919,27 +919,19 @@ public final class ListMonitor<T: NSManagedObject> {
|
|||||||
|
|
||||||
private init(dataStack: DataStack, from: From<T>, sectionBy: SectionBy?, fetchClauses: [FetchClause], prepareFetch: (ListMonitor<T>, () -> Void) -> Void) {
|
private init(dataStack: DataStack, from: From<T>, sectionBy: SectionBy?, fetchClauses: [FetchClause], prepareFetch: (ListMonitor<T>, () -> Void) -> Void) {
|
||||||
|
|
||||||
let context = dataStack.mainContext
|
|
||||||
|
|
||||||
let fetchRequest = NSFetchRequest()
|
let fetchRequest = NSFetchRequest()
|
||||||
from.applyToFetchRequest(fetchRequest, context: context)
|
|
||||||
|
|
||||||
fetchRequest.fetchLimit = 0
|
fetchRequest.fetchLimit = 0
|
||||||
fetchRequest.resultType = .ManagedObjectResultType
|
fetchRequest.resultType = .ManagedObjectResultType
|
||||||
fetchRequest.fetchBatchSize = 20
|
fetchRequest.fetchBatchSize = 20
|
||||||
fetchRequest.includesPendingChanges = false
|
fetchRequest.includesPendingChanges = false
|
||||||
fetchRequest.shouldRefreshRefetchedObjects = true
|
fetchRequest.shouldRefreshRefetchedObjects = true
|
||||||
|
|
||||||
for clause in fetchClauses {
|
|
||||||
|
|
||||||
clause.applyToFetchRequest(fetchRequest)
|
|
||||||
}
|
|
||||||
|
|
||||||
let fetchedResultsController = NSFetchedResultsController(
|
let fetchedResultsController = NSFetchedResultsController(
|
||||||
|
dataStack: dataStack,
|
||||||
fetchRequest: fetchRequest,
|
fetchRequest: fetchRequest,
|
||||||
managedObjectContext: context,
|
from: from,
|
||||||
sectionNameKeyPath: sectionBy?.sectionKeyPath,
|
sectionBy: sectionBy,
|
||||||
cacheName: nil
|
fetchClauses: fetchClauses
|
||||||
)
|
)
|
||||||
|
|
||||||
let fetchedResultsControllerDelegate = FetchedResultsControllerDelegate()
|
let fetchedResultsControllerDelegate = FetchedResultsControllerDelegate()
|
||||||
|
|||||||
@@ -167,25 +167,18 @@ public final class ObjectMonitor<T: NSManagedObject> {
|
|||||||
|
|
||||||
internal init(dataStack: DataStack, object: T) {
|
internal init(dataStack: DataStack, object: T) {
|
||||||
|
|
||||||
let context = dataStack.mainContext
|
|
||||||
|
|
||||||
let fetchRequest = NSFetchRequest()
|
let fetchRequest = NSFetchRequest()
|
||||||
fetchRequest.entity = object.entity
|
fetchRequest.entity = object.entity
|
||||||
|
|
||||||
fetchRequest.fetchLimit = 0
|
fetchRequest.fetchLimit = 0
|
||||||
fetchRequest.resultType = .ManagedObjectResultType
|
fetchRequest.resultType = .ManagedObjectResultType
|
||||||
fetchRequest.sortDescriptors = []
|
fetchRequest.sortDescriptors = []
|
||||||
fetchRequest.includesPendingChanges = false
|
fetchRequest.includesPendingChanges = false
|
||||||
fetchRequest.shouldRefreshRefetchedObjects = true
|
fetchRequest.shouldRefreshRefetchedObjects = true
|
||||||
|
|
||||||
let originalObjectID = object.objectID
|
|
||||||
Where("SELF", isEqualTo: originalObjectID).applyToFetchRequest(fetchRequest)
|
|
||||||
|
|
||||||
let fetchedResultsController = NSFetchedResultsController(
|
let fetchedResultsController = NSFetchedResultsController(
|
||||||
|
dataStack: dataStack,
|
||||||
fetchRequest: fetchRequest,
|
fetchRequest: fetchRequest,
|
||||||
managedObjectContext: context,
|
fetchClauses: [Where("SELF", isEqualTo: object.objectID)]
|
||||||
sectionNameKeyPath: nil,
|
|
||||||
cacheName: nil
|
|
||||||
)
|
)
|
||||||
|
|
||||||
let fetchedResultsControllerDelegate = FetchedResultsControllerDelegate()
|
let fetchedResultsControllerDelegate = FetchedResultsControllerDelegate()
|
||||||
|
|||||||
Reference in New Issue
Block a user