diff --git a/CoreStore.xcodeproj/project.pbxproj b/CoreStore.xcodeproj/project.pbxproj index 125ae7a..10d86b3 100644 --- a/CoreStore.xcodeproj/project.pbxproj +++ b/CoreStore.xcodeproj/project.pbxproj @@ -87,6 +87,11 @@ 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 */; }; + B52661401CADD585007B85D9 /* CoreStoreFetchRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B526613F1CADD585007B85D9 /* CoreStoreFetchRequest.swift */; }; + B52661411CADD585007B85D9 /* CoreStoreFetchRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B526613F1CADD585007B85D9 /* CoreStoreFetchRequest.swift */; }; + B52661421CADD585007B85D9 /* CoreStoreFetchRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B526613F1CADD585007B85D9 /* CoreStoreFetchRequest.swift */; }; + B52661431CADD585007B85D9 /* CoreStoreFetchRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B526613F1CADD585007B85D9 /* CoreStoreFetchRequest.swift */; }; + B52661441CADD585007B85D9 /* CoreStoreFetchRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B526613F1CADD585007B85D9 /* CoreStoreFetchRequest.swift */; }; B52DD17E1BE1F8CD00949AFE /* CoreStore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B52DD1741BE1F8CC00949AFE /* CoreStore.framework */; }; B52DD1911BE1F8EB00949AFE /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5548CD51BD65AE00077652A /* Foundation.framework */; }; B52DD1921BE1F8F000949AFE /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5548CD71BD65AE50077652A /* CoreData.framework */; }; @@ -378,6 +383,7 @@ B519E4571C4CD2CA00E7B469 /* GCDKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GCDKit.framework; path = "../../Library/Developer/Xcode/DerivedData/Build/Products/Debug-iphoneos/GCDKit.framework"; sourceTree = ""; }; B51BE0691B47FC4B0069F532 /* NSManagedObjectModel+Setup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSManagedObjectModel+Setup.swift"; sourceTree = ""; }; B5202CF91C04688100DED140 /* NSFetchedResultsController+Convenience.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSFetchedResultsController+Convenience.swift"; sourceTree = ""; }; + B526613F1CADD585007B85D9 /* CoreStoreFetchRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreStoreFetchRequest.swift; sourceTree = ""; }; 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; }; B54A6A541BA15F2A007870FD /* FetchedResultsControllerDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchedResultsControllerDelegate.swift; sourceTree = ""; }; @@ -766,6 +772,7 @@ B5E84F2B1AFF849C0064E85B /* NotificationObserver.swift */, B59D5C211B5BA34B00453479 /* NSFileManager+Setup.swift */, B5C976E61C6E3A5900B1AF90 /* CoreStoreFetchedResultsController.swift */, + B526613F1CADD585007B85D9 /* CoreStoreFetchRequest.swift */, B5E84F2C1AFF849C0064E85B /* NSManagedObjectContext+CoreStore.swift */, B5E84F351AFF85470064E85B /* NSManagedObjectContext+Querying.swift */, B5E84F321AFF85470064E85B /* NSManagedObjectContext+Setup.swift */, @@ -1110,6 +1117,7 @@ B56007111B3F6BD500A9A8F9 /* Into.swift in Sources */, B5E84F111AFF847B0064E85B /* Select.swift in Sources */, B50392F91C478FF3009900CA /* NSManagedObject+Transaction.swift in Sources */, + B52661401CADD585007B85D9 /* CoreStoreFetchRequest.swift in Sources */, B5202CFA1C04688100DED140 /* NSFetchedResultsController+Convenience.swift in Sources */, B5E84EE11AFF84500064E85B /* PersistentStoreResult.swift in Sources */, B5E84F251AFF84860064E85B /* ObjectObserver.swift in Sources */, @@ -1188,6 +1196,7 @@ 82BA18DD1C4BBE1400A0916E /* NSFetchedResultsController+Convenience.swift in Sources */, 82BA18B41C4BBD3900A0916E /* BaseDataTransaction+Importing.swift in Sources */, 82BA18CA1C4BBD5900A0916E /* MigrationResult.swift in Sources */, + B52661421CADD585007B85D9 /* CoreStoreFetchRequest.swift in Sources */, 82BA18C11C4BBD5300A0916E /* CoreStore+Observing.swift in Sources */, 82BA18BC1C4BBD4A00A0916E /* OrderBy.swift in Sources */, 82BA18B01C4BBD3100A0916E /* NSManagedObject+Transaction.swift in Sources */, @@ -1266,6 +1275,7 @@ B52DD1C71BE1F94600949AFE /* NSManagedObjectContext+Querying.swift in Sources */, B52DD1C81BE1F94600949AFE /* NSManagedObjectContext+Setup.swift in Sources */, B52DD1C31BE1F94600949AFE /* NotificationObserver.swift in Sources */, + B52661441CADD585007B85D9 /* CoreStoreFetchRequest.swift in Sources */, B52DD1A81BE1F93200949AFE /* DataStack+Querying.swift in Sources */, B52DD1BC1BE1F94000949AFE /* MigrationResult.swift in Sources */, B52DD19D1BE1F92C00949AFE /* BaseDataTransaction.swift in Sources */, @@ -1333,6 +1343,7 @@ B5202CFD1C046E8400DED140 /* NSFetchedResultsController+Convenience.swift in Sources */, B56321AF1BD6521C006C9394 /* NSFileManager+Setup.swift in Sources */, B50392FA1C47963F009900CA /* NSManagedObject+Transaction.swift in Sources */, + B52661431CADD585007B85D9 /* CoreStoreFetchRequest.swift in Sources */, B56321971BD65216006C9394 /* Select.swift in Sources */, B56321AB1BD6521C006C9394 /* FetchedResultsControllerDelegate.swift in Sources */, B56321821BD65216006C9394 /* PersistentStoreResult.swift in Sources */, @@ -1392,6 +1403,7 @@ B5D9E2F71CA2C317007A9D52 /* DataStack+Querying.swift in Sources */, B5D9E2F81CA2C317007A9D52 /* SectionBy.swift in Sources */, B5D9E2F91CA2C317007A9D52 /* NSManagedObjectContext+Transaction.swift in Sources */, + B52661411CADD585007B85D9 /* CoreStoreFetchRequest.swift in Sources */, B5D9E2FA1CA2C317007A9D52 /* UnsafeDataTransaction+Observing.swift in Sources */, B5D9E2FB1CA2C317007A9D52 /* MigrationChain.swift in Sources */, B5D9E2FC1CA2C317007A9D52 /* Tweak.swift in Sources */, diff --git a/CoreStore/Internal/CoreStoreFetchRequest.swift b/CoreStore/Internal/CoreStoreFetchRequest.swift new file mode 100644 index 0000000..e3bce41 --- /dev/null +++ b/CoreStore/Internal/CoreStoreFetchRequest.swift @@ -0,0 +1,43 @@ +// +// CoreStoreFetchRequest.swift +// CoreStore +// +// Copyright © 2016 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: - CoreStoreFetchRequest + +// Bugfix for NSFetchRequest messing up memory management for `affectedStores` +// http://stackoverflow.com/questions/14396375/nsfetchedresultscontroller-crashes-in-ios-6-if-affectedstores-is-specified +internal final class CoreStoreFetchRequest: NSFetchRequest { + + override var affectedStores: [NSPersistentStore]? { + + get { return self.safeAffectedStores } + set { self.safeAffectedStores = newValue } + } + + private var safeAffectedStores: [NSPersistentStore]? +} diff --git a/CoreStore/Internal/CoreStoreFetchedResultsController.swift b/CoreStore/Internal/CoreStoreFetchedResultsController.swift index cb6c7e2..1286713 100644 --- a/CoreStore/Internal/CoreStoreFetchedResultsController.swift +++ b/CoreStore/Internal/CoreStoreFetchedResultsController.swift @@ -104,19 +104,3 @@ internal final class CoreStoreFetchedResultsController: NSFe private let reapplyAffectedStores: (fetchRequest: NSFetchRequest, context: NSManagedObjectContext) -> Bool } - - -// MARK: - CoreStoreFetchRequest - -// Bugfix for NSFetchRequest messing up memory management for `affectedStores` -// http://stackoverflow.com/questions/14396375/nsfetchedresultscontroller-crashes-in-ios-6-if-affectedstores-is-specified -internal final class CoreStoreFetchRequest: NSFetchRequest { - - override var affectedStores: [NSPersistentStore]? { - - get { return self.safeAffectedStores } - set { self.safeAffectedStores = newValue } - } - - private var safeAffectedStores: [NSPersistentStore]? -}