From df866718cf83572409097505c08eb1697552c4f9 Mon Sep 17 00:00:00 2001 From: John Rommel Estropia Date: Tue, 9 Feb 2016 07:35:31 +0900 Subject: [PATCH] tidy up --- CoreStore.xcodeproj/project.pbxproj | 4 ++ .../Internal/NSManagedObjectModel+Setup.swift | 4 +- .../NSPersistentStoreCoordinator+Setup.swift | 64 +++++++++++++++++++ CoreStore/Internal/WeakObject.swift | 5 +- CoreStore/Observing/ListMonitor.swift | 2 +- 5 files changed, 72 insertions(+), 7 deletions(-) create mode 100644 CoreStore/Internal/NSPersistentStoreCoordinator+Setup.swift diff --git a/CoreStore.xcodeproj/project.pbxproj b/CoreStore.xcodeproj/project.pbxproj index eea6690..afc7d19 100644 --- a/CoreStore.xcodeproj/project.pbxproj +++ b/CoreStore.xcodeproj/project.pbxproj @@ -206,6 +206,7 @@ B56321B61BD6521C006C9394 /* WeakObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2D1AFF849C0064E85B /* WeakObject.swift */; }; B56964D41B22FFAD0075EE4A /* DataStack+Migration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B56964D31B22FFAD0075EE4A /* DataStack+Migration.swift */; }; B56965241B356B820075EE4A /* MigrationResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = B56965231B356B820075EE4A /* MigrationResult.swift */; }; + B59AFF411C6593E400C0ABE2 /* NSPersistentStoreCoordinator+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59AFF401C6593E400C0ABE2 /* NSPersistentStoreCoordinator+Setup.swift */; }; B59D5C221B5BA34B00453479 /* NSFileManager+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59D5C211B5BA34B00453479 /* NSFileManager+Setup.swift */; }; B5A261211B64BFDB006EB6D3 /* MigrationType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A261201B64BFDB006EB6D3 /* MigrationType.swift */; }; B5C976E31C6C9F6A00B1AF90 /* UnsafeDataTransaction+Observing.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C976E21C6C9F6A00B1AF90 /* UnsafeDataTransaction+Observing.swift */; }; @@ -319,6 +320,7 @@ B563217B1BD650E3006C9394 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/WatchOS.platform/Developer/SDKs/WatchOS2.0.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; }; B56964D31B22FFAD0075EE4A /* DataStack+Migration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DataStack+Migration.swift"; sourceTree = ""; }; B56965231B356B820075EE4A /* MigrationResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MigrationResult.swift; sourceTree = ""; }; + B59AFF401C6593E400C0ABE2 /* NSPersistentStoreCoordinator+Setup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSPersistentStoreCoordinator+Setup.swift"; sourceTree = ""; }; B59D5C211B5BA34B00453479 /* NSFileManager+Setup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSFileManager+Setup.swift"; sourceTree = ""; }; B5A261201B64BFDB006EB6D3 /* MigrationType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MigrationType.swift; sourceTree = ""; }; B5BDC91A1C202269008147CD /* CartFile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CartFile; sourceTree = ""; }; @@ -669,6 +671,7 @@ B5E84F321AFF85470064E85B /* NSManagedObjectContext+Setup.swift */, B5E84F331AFF85470064E85B /* NSManagedObjectContext+Transaction.swift */, B51BE0691B47FC4B0069F532 /* NSManagedObjectModel+Setup.swift */, + B59AFF401C6593E400C0ABE2 /* NSPersistentStoreCoordinator+Setup.swift */, B5E84F2D1AFF849C0064E85B /* WeakObject.swift */, ); path = Internal; @@ -985,6 +988,7 @@ B5FAD6AC1B51285300714891 /* MigrationManager.swift in Sources */, B5E84EF61AFF846E0064E85B /* DataStack+Transaction.swift in Sources */, B5E84EDF1AFF84500064E85B /* DataStack.swift in Sources */, + B59AFF411C6593E400C0ABE2 /* NSPersistentStoreCoordinator+Setup.swift in Sources */, B5E834BB1B7691F3001D3D50 /* Functions.swift in Sources */, B5E84F231AFF84860064E85B /* ListMonitor.swift in Sources */, B5E84EF71AFF846E0064E85B /* UnsafeDataTransaction.swift in Sources */, diff --git a/CoreStore/Internal/NSManagedObjectModel+Setup.swift b/CoreStore/Internal/NSManagedObjectModel+Setup.swift index ef22705..87fd899 100644 --- a/CoreStore/Internal/NSManagedObjectModel+Setup.swift +++ b/CoreStore/Internal/NSManagedObjectModel+Setup.swift @@ -108,7 +108,7 @@ internal extension NSManagedObjectModel { fatalError("Could not create an \(typeName(NSManagedObjectModel)) from the model at URL \"\(modelFileURL)\".") } - @nonobjc private(set) internal var currentModelVersion: String? { + @nonobjc internal private(set) var currentModelVersion: String? { get { @@ -128,7 +128,7 @@ internal extension NSManagedObjectModel { } } - @nonobjc private(set) internal var modelVersions: Set? { + @nonobjc internal private(set) var modelVersions: Set? { get { diff --git a/CoreStore/Internal/NSPersistentStoreCoordinator+Setup.swift b/CoreStore/Internal/NSPersistentStoreCoordinator+Setup.swift new file mode 100644 index 0000000..d135629 --- /dev/null +++ b/CoreStore/Internal/NSPersistentStoreCoordinator+Setup.swift @@ -0,0 +1,64 @@ +// +// NSPersistentStoreCoordinator+Setup.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: - NSPersistentStoreCoordinator + +internal extension NSPersistentStoreCoordinator { + + // MARK: Internal + + internal func addPersistentStoreSynchronously(storeType: String, configuration: String?, URL storeURL: NSURL?, options: [NSObject : AnyObject]?) throws -> NSPersistentStore { + + var store: NSPersistentStore? + var storeError: NSError? + self.performBlockAndWait { + + do { + + store = try self.addPersistentStoreWithType( + storeType, + configuration: configuration, + URL: storeURL, + options: options + ) + } + catch { + + storeError = error as NSError + } + } + + if let store = store { + + return store + } + + throw storeError ?? NSError(coreStoreErrorCode: .UnknownError) + } +} \ No newline at end of file diff --git a/CoreStore/Internal/WeakObject.swift b/CoreStore/Internal/WeakObject.swift index 3afab96..0b76a45 100644 --- a/CoreStore/Internal/WeakObject.swift +++ b/CoreStore/Internal/WeakObject.swift @@ -37,8 +37,5 @@ internal final class WeakObject { self.object = object } - - // MARK: Private - - private(set) weak var object: AnyObject? + internal private(set) weak var object: AnyObject? } diff --git a/CoreStore/Observing/ListMonitor.swift b/CoreStore/Observing/ListMonitor.swift index fd0f540..b6e3e86 100644 --- a/CoreStore/Observing/ListMonitor.swift +++ b/CoreStore/Observing/ListMonitor.swift @@ -854,7 +854,7 @@ public final class ListMonitor { /** Returns `true` if a call to `refetch(...)` was made to the `ListMonitor` and is currently waiting for the fetching to complete. Returns `false` otherwise. */ - private(set) public var isPendingRefetch = false + public private(set) var isPendingRefetch = false /** Asks the `ListMonitor` to refetch its objects using the specified series of `FetchClause`s. Note that this method does not execute the fetch immediately; the actual fetching will happen after the `NSFetchedResultsController`'s last `controllerDidChangeContent(_:)` notification completes.