From 0ba63c6e726bd40e88e314411ef470d37c510c33 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Tue, 6 Sep 2016 09:57:28 +0900 Subject: [PATCH] WIP: Xcode 8 beta 6 --- Cartfile | 1 - CoreStore.podspec | 4 +- CoreStore.xcodeproj/project.pbxproj | 20 +++-- CoreStoreTests/FetchTests.swift | 5 +- CoreStoreTests/TransactionTests.swift | 3 +- .../Convenience/NSProgress+Convenience.swift | 9 +- Sources/CoreStore.swift | 13 ++- Sources/CoreStoreError.swift | 4 +- .../BaseDataTransaction+Querying.swift | 4 +- .../Concrete Clauses/From.swift | 6 +- .../Concrete Clauses/OrderBy.swift | 10 +-- .../Concrete Clauses/Select.swift | 6 +- .../Concrete Clauses/Tweak.swift | 6 +- .../Concrete Clauses/Where.swift | 26 +++--- .../CoreStore+Querying.swift | 4 +- .../DataStack+Querying.swift | 7 +- .../BaseDataTransaction+Importing.swift | 22 ++--- .../CoreStoreFetchedResultsController.swift | 10 +-- .../Internal/DispatchQueue+CoreStore.swift | 90 +++++++++++++++++++ Sources/Internal/Functions.swift | 10 +-- .../NSManagedObjectContext+CoreStore.swift | 3 - .../NSManagedObjectContext+Querying.swift | 18 ++-- .../NSManagedObjectContext+Transaction.swift | 11 +-- .../Internal/NSManagedObjectModel+Setup.swift | 2 +- .../NSPersistentStoreCoordinator+Setup.swift | 12 +-- Sources/Internal/NotificationObserver.swift | 2 +- ...reStore+CustomDebugStringConvertible.swift | 6 +- Sources/Logging/CoreStore+Logging.swift | 4 +- Sources/Migrating/CoreStore+Migration.swift | 7 +- Sources/Migrating/DataStack+Migration.swift | 81 ++++++++--------- Sources/Migrating/MigrationChain.swift | 12 +-- Sources/Migrating/MigrationResult.swift | 13 +-- Sources/Migrating/MigrationType.swift | 10 +-- Sources/Migrating/SetupResult.swift | 11 +-- .../CSAsynchronousDataTransaction.swift | 8 +- .../ObjectiveC/CSBaseDataTransaction.swift | 2 +- .../ObjectiveC/CSCoreStore+Transaction.swift | 6 +- .../ObjectiveC/CSDataStack+Transaction.swift | 6 +- Sources/ObjectiveC/CSDataStack.swift | 4 +- Sources/ObjectiveC/CSError.swift | 20 ++--- Sources/ObjectiveC/CSFrom.swift | 2 +- Sources/ObjectiveC/CSGroupBy.swift | 4 +- Sources/ObjectiveC/CSInMemoryStore.swift | 4 +- Sources/ObjectiveC/CSInto.swift | 4 +- Sources/ObjectiveC/CSListMonitor.swift | 4 +- Sources/ObjectiveC/CSMigrationResult.swift | 18 ++-- Sources/ObjectiveC/CSMigrationType.swift | 4 +- Sources/ObjectiveC/CSObjectMonitor.swift | 4 +- Sources/ObjectiveC/CSOrderBy.swift | 4 +- Sources/ObjectiveC/CSSQliteStore.swift | 4 +- Sources/ObjectiveC/CSSaveResult.swift | 18 ++-- Sources/ObjectiveC/CSSectionBy.swift | 4 +- Sources/ObjectiveC/CSSelect.swift | 8 +- Sources/ObjectiveC/CSSetupResult.swift | 20 ++--- .../CSSynchronousDataTransaction.swift | 4 +- Sources/ObjectiveC/CSTweak.swift | 6 +- .../ObjectiveC/CSUnsafeDataTransaction.swift | 6 +- Sources/ObjectiveC/CSWhere.swift | 4 +- Sources/ObjectiveC/CoreStoreBridge.swift | 16 ++-- .../ObjectiveC/NSProgress+ObjectiveC.swift | 2 +- Sources/Observing/DataStack+Observing.swift | 3 - Sources/Observing/ListMonitor.swift | 63 ++++++------- Sources/Observing/ObjectMonitor.swift | 42 ++++----- Sources/Observing/SectionBy.swift | 4 +- .../UnsafeDataTransaction+Observing.swift | 3 - Sources/Setup/CoreStore+Setup.swift | 7 +- Sources/Setup/DataStack.swift | 33 +++---- .../Setup/StorageInterfaces/ICloudStore.swift | 8 +- .../StorageInterfaces/LegacySQLiteStore.swift | 7 +- .../Setup/StorageInterfaces/SQLiteStore.swift | 11 +-- .../StorageInterfaces/StorageInterface.swift | 12 +-- .../AsynchronousDataTransaction.swift | 17 ++-- .../Transactions/BaseDataTransaction.swift | 13 ++- .../Transactions/CoreStore+Transaction.swift | 4 +- .../Transactions/DataStack+Transaction.swift | 7 +- Sources/Transactions/SaveResult.swift | 28 +++--- .../SynchronousDataTransaction.swift | 11 +-- .../Transactions/UnsafeDataTransaction.swift | 11 +-- 78 files changed, 472 insertions(+), 450 deletions(-) create mode 100644 Sources/Internal/DispatchQueue+CoreStore.swift diff --git a/Cartfile b/Cartfile index b322e93..e69de29 100644 --- a/Cartfile +++ b/Cartfile @@ -1 +0,0 @@ -github "JohnEstropia/GCDKit" == 1.2.6 diff --git a/CoreStore.podspec b/CoreStore.podspec index dd137c4..9c9755f 100644 --- a/CoreStore.podspec +++ b/CoreStore.podspec @@ -18,6 +18,4 @@ Pod::Spec.new do |s| s.requires_arc = true s.pod_target_xcconfig = { 'OTHER_SWIFT_FLAGS' => '-D USE_FRAMEWORKS', 'GCC_PREPROCESSOR_DEFINITIONS' => 'USE_FRAMEWORKS=1' } - - s.dependency "GCDKit", "1.2.6" -end \ No newline at end of file +end diff --git a/CoreStore.xcodeproj/project.pbxproj b/CoreStore.xcodeproj/project.pbxproj index 5f15666..c44a55a 100644 --- a/CoreStore.xcodeproj/project.pbxproj +++ b/CoreStore.xcodeproj/project.pbxproj @@ -193,6 +193,10 @@ B52DD1C91BE1F94600949AFE /* NSManagedObjectContext+Transaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F331AFF85470064E85B /* NSManagedObjectContext+Transaction.swift */; }; B52DD1CA1BE1F94600949AFE /* NSManagedObjectModel+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51BE0691B47FC4B0069F532 /* NSManagedObjectModel+Setup.swift */; }; B52DD1CB1BE1F94600949AFE /* WeakObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E84F2D1AFF849C0064E85B /* WeakObject.swift */; }; + B533C4DB1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B533C4DA1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift */; }; + B533C4DC1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B533C4DA1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift */; }; + B533C4DD1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B533C4DA1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift */; }; + B533C4DE1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B533C4DA1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift */; }; B538BA771D15B3E30003A766 /* CoreStoreBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = B538BA701D15B3E30003A766 /* CoreStoreBridge.m */; }; B538BA781D15B3E30003A766 /* CoreStoreBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = B538BA701D15B3E30003A766 /* CoreStoreBridge.m */; }; B538BA791D15B3E30003A766 /* CoreStoreBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = B538BA701D15B3E30003A766 /* CoreStoreBridge.m */; }; @@ -604,6 +608,7 @@ B529C2031CA4A2DB007E7EBD /* CSSaveResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSSaveResult.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; }; + B533C4DA1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DispatchQueue+CoreStore.swift"; sourceTree = ""; }; B538BA701D15B3E30003A766 /* CoreStoreBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CoreStoreBridge.m; sourceTree = ""; }; B53FB9FD1CAB2D2F00F0D40A /* CSMigrationResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSMigrationResult.swift; sourceTree = ""; }; B53FBA031CAB300C00F0D40A /* CSMigrationType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSMigrationType.swift; sourceTree = ""; }; @@ -1199,6 +1204,7 @@ B5E834BA1B7691F3001D3D50 /* Functions.swift */, B5FAD6AB1B51285300714891 /* MigrationManager.swift */, B5E84F2B1AFF849C0064E85B /* NotificationObserver.swift */, + B533C4DA1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift */, B5E84F2C1AFF849C0064E85B /* NSManagedObjectContext+CoreStore.swift */, B5E84F351AFF85470064E85B /* NSManagedObjectContext+Querying.swift */, B5E84F321AFF85470064E85B /* NSManagedObjectContext+Setup.swift */, @@ -1614,6 +1620,7 @@ B5E2222A1CA51B6E00BA2E95 /* CSUnsafeDataTransaction.swift in Sources */, B5E84F391AFF85470064E85B /* NSManagedObjectContext+Querying.swift in Sources */, B5E84EE81AFF84610064E85B /* CoreStoreLogger.swift in Sources */, + B533C4DB1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift in Sources */, B559CD491CAA8C6D00E4D58B /* CSStorageInterface.swift in Sources */, B5ECDC2F1CA81CDC00C7F112 /* CSCoreStore+Transaction.swift in Sources */, B5E84F311AFF849C0064E85B /* WeakObject.swift in Sources */, @@ -1762,6 +1769,7 @@ 82BA18A71C4BBD2900A0916E /* CoreStore+Logging.swift in Sources */, 82BA18D81C4BBD7100A0916E /* WeakObject.swift in Sources */, B559CD4B1CAA8C6D00E4D58B /* CSStorageInterface.swift in Sources */, + B533C4DC1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift in Sources */, B5ECDC311CA81CDC00C7F112 /* CSCoreStore+Transaction.swift in Sources */, 82BA18AF1C4BBD3100A0916E /* CoreStore+Transaction.swift in Sources */, 82BA18CB1C4BBD6400A0916E /* NSManagedObject+Convenience.swift in Sources */, @@ -1910,6 +1918,7 @@ B52DD1A71BE1F93200949AFE /* BaseDataTransaction+Querying.swift in Sources */, B546F96C1C9AF26D00D5AC55 /* CSInMemoryStore.swift in Sources */, B52DD1C61BE1F94600949AFE /* NSManagedObjectContext+CoreStore.swift in Sources */, + B533C4DE1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift in Sources */, B5220E141D130614009BC71E /* DataStack+Observing.swift in Sources */, B52DD1A21BE1F92C00949AFE /* CoreStore+Transaction.swift in Sources */, B5E2222E1CA51B6E00BA2E95 /* CSUnsafeDataTransaction.swift in Sources */, @@ -2058,6 +2067,7 @@ B563219F1BD65216006C9394 /* ObjectMonitor.swift in Sources */, B56321B61BD6521C006C9394 /* WeakObject.swift in Sources */, B559CD4C1CAA8C6D00E4D58B /* CSStorageInterface.swift in Sources */, + B533C4DD1D7D4BFA001383CB /* DispatchQueue+CoreStore.swift in Sources */, B5ECDC321CA81CDC00C7F112 /* CSCoreStore+Transaction.swift in Sources */, B56321AC1BD6521C006C9394 /* Functions.swift in Sources */, B56321851BD65216006C9394 /* CoreStore+Logging.swift in Sources */, @@ -2289,10 +2299,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/Carthage/Checkouts/GCDKit/build/Debug-appletvos", - ); + FRAMEWORK_SEARCH_PATHS = "$(inherited)"; GCC_NO_COMMON_BLOCKS = YES; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -2311,10 +2318,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/Carthage/Checkouts/GCDKit/build/Debug-appletvos", - ); + FRAMEWORK_SEARCH_PATHS = "$(inherited)"; GCC_NO_COMMON_BLOCKS = YES; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; diff --git a/CoreStoreTests/FetchTests.swift b/CoreStoreTests/FetchTests.swift index 7e03514..b76c100 100644 --- a/CoreStoreTests/FetchTests.swift +++ b/CoreStoreTests/FetchTests.swift @@ -24,7 +24,6 @@ // import XCTest -import GCDKit @testable import CoreStore @@ -97,7 +96,7 @@ final class FetchTests: BaseTestDataTestCase { XCTAssertEqual(existing1!.objectID, object.objectID) XCTAssertEqual(existing1!.managedObjectContext, transaction.context) - GCDQueue.main.async { + DispatchQueue.main.async { let existing2 = stack.fetchExisting(existing1!) XCTAssertNotNil(existing2) @@ -204,7 +203,7 @@ final class FetchTests: BaseTestDataTestCase { XCTAssertEqual(object.managedObjectContext, transaction.context) } - GCDQueue.main.async { + DispatchQueue.main.async { let existing2 = stack.fetchExisting(existing1) XCTAssertEqual( diff --git a/CoreStoreTests/TransactionTests.swift b/CoreStoreTests/TransactionTests.swift index ffc1364..c16c65f 100644 --- a/CoreStoreTests/TransactionTests.swift +++ b/CoreStoreTests/TransactionTests.swift @@ -24,7 +24,6 @@ // import XCTest -import GCDKit @testable import CoreStore @@ -651,7 +650,7 @@ final class TransactionTests: BaseTestCase { transaction.delete(object) - GCDQueue.main.async { + DispatchQueue.main.async { XCTAssertEqual(stack.fetchCount(From()), 1) diff --git a/Sources/Convenience/NSProgress+Convenience.swift b/Sources/Convenience/NSProgress+Convenience.swift index 4135086..0597074 100644 --- a/Sources/Convenience/NSProgress+Convenience.swift +++ b/Sources/Convenience/NSProgress+Convenience.swift @@ -24,9 +24,6 @@ // import Foundation -#if USE_FRAMEWORKS - import GCDKit -#endif // MARK: - NSProgress @@ -39,7 +36,7 @@ public extension Progress { - parameter closure: the closure to execute on progress change */ @nonobjc - public func setProgressHandler(_ closure: ((progress: Progress) -> Void)?) { + public func setProgressHandler(_ closure: ((_ progress: Progress) -> Void)?) { self.progressObserver.progressHandler = closure } @@ -82,7 +79,7 @@ public extension Progress { private final class ProgressObserver: NSObject { private unowned let progress: Progress - private var progressHandler: ((progress: Progress) -> Void)? { + private var progressHandler: ((_ progress: Progress) -> Void)? { didSet { @@ -132,7 +129,7 @@ private final class ProgressObserver: NSObject { return } - GCDQueue.main.async { [weak self] () -> Void in + DispatchQueue.main.async { [weak self] () -> Void in self?.progressHandler?(progress: progress) } diff --git a/Sources/CoreStore.swift b/Sources/CoreStore.swift index e26c83f..c802015 100644 --- a/Sources/CoreStore.swift +++ b/Sources/CoreStore.swift @@ -24,9 +24,6 @@ // import CoreData -#if USE_FRAMEWORKS - import GCDKit -#endif // MARK: - CoreStore @@ -45,10 +42,10 @@ public enum CoreStore { get { - self.defaultStackBarrierQueue.barrierSync { - + self.defaultStackBarrierQueue.sync(flags: .barrier) { + if self.defaultStackInstance == nil { - + self.defaultStackInstance = DataStack() } } @@ -56,7 +53,7 @@ public enum CoreStore { } set { - self.defaultStackBarrierQueue.barrierAsync { + self.defaultStackBarrierQueue.async(flags: .barrier) { self.defaultStackInstance = newValue } @@ -66,7 +63,7 @@ public enum CoreStore { // MARK: Private - private static let defaultStackBarrierQueue = GCDQueue.createConcurrent("com.coreStore.defaultStackBarrierQueue") + private static let defaultStackBarrierQueue = DispatchQueue(concurrentWith: "com.coreStore.defaultStackBarrierQueue") private static var defaultStackInstance: DataStack? } diff --git a/Sources/CoreStoreError.swift b/Sources/CoreStoreError.swift index 076f41a..d5013df 100644 --- a/Sources/CoreStoreError.swift +++ b/Sources/CoreStoreError.swift @@ -32,7 +32,7 @@ import CoreData /** All errors thrown from CoreStore are expressed in `CoreStoreError` enum values. */ -public enum CoreStoreError: ErrorProtocol, Hashable { +public enum CoreStoreError: Error, Hashable { /** A failure occured because of an unknown error. @@ -116,7 +116,7 @@ public enum CoreStoreError: ErrorProtocol, Hashable { // MARK: Internal - internal init(_ error: ErrorProtocol?) { + internal init(_ error: Error?) { self = error.flatMap { $0.bridgeToSwift } ?? .unknown } diff --git a/Sources/Fetching and Querying/BaseDataTransaction+Querying.swift b/Sources/Fetching and Querying/BaseDataTransaction+Querying.swift index df36237..cc63f76 100644 --- a/Sources/Fetching and Querying/BaseDataTransaction+Querying.swift +++ b/Sources/Fetching and Querying/BaseDataTransaction+Querying.swift @@ -73,7 +73,7 @@ public extension BaseDataTransaction { - parameter objects: an array of `NSManagedObject`s created/fetched outside the transaction - returns: the `NSManagedObject` array for objects that exists in the transaction */ - public func fetchExisting(_ objects: S) -> [T] { + public func fetchExisting(_ objects: S) -> [T] where S.Iterator.Element == T { return objects.flatMap { (try? self.context.existingObject(with: $0.objectID)) as? T } } @@ -84,7 +84,7 @@ public extension BaseDataTransaction { - parameter objectIDs: the `NSManagedObjectID` array for the objects - returns: the `NSManagedObject` array for objects that exists in the transaction */ - public func fetchExisting(_ objectIDs: S) -> [T] { + public func fetchExisting(_ objectIDs: S) -> [T] where S.Iterator.Element == NSManagedObjectID { return objectIDs.flatMap { (try? self.context.existingObject(with: $0)) as? T } } diff --git a/Sources/Fetching and Querying/Concrete Clauses/From.swift b/Sources/Fetching and Querying/Concrete Clauses/From.swift index 83038f3..c0bb44e 100644 --- a/Sources/Fetching and Querying/Concrete Clauses/From.swift +++ b/Sources/Fetching and Querying/Concrete Clauses/From.swift @@ -201,7 +201,7 @@ public struct From { internal func applyAffectedStoresForFetchedRequest(_ fetchRequest: NSFetchRequest, context: NSManagedObjectContext) -> Bool { - let stores = self.findPersistentStores(context: context) + let stores = self.findPersistentStores(context) fetchRequest.affectedStores = stores return stores?.isEmpty == false } @@ -218,7 +218,7 @@ public struct From { // MARK: Private - private let findPersistentStores: (context: NSManagedObjectContext) -> [NSPersistentStore]? + private let findPersistentStores: (_ context: NSManagedObjectContext) -> [NSPersistentStore]? private init(entityClass: AnyClass, configurations: [String?]?) { @@ -244,7 +244,7 @@ public struct From { } } - private init(entityClass: AnyClass, configurations: [String?]?, findPersistentStores: (context: NSManagedObjectContext) -> [NSPersistentStore]?) { + private init(entityClass: AnyClass, configurations: [String?]?, findPersistentStores: @escaping (_ context: NSManagedObjectContext) -> [NSPersistentStore]?) { self.entityClass = entityClass self.configurations = configurations diff --git a/Sources/Fetching and Querying/Concrete Clauses/OrderBy.swift b/Sources/Fetching and Querying/Concrete Clauses/OrderBy.swift index 7063cb2..f1152d6 100644 --- a/Sources/Fetching and Querying/Concrete Clauses/OrderBy.swift +++ b/Sources/Fetching and Querying/Concrete Clauses/OrderBy.swift @@ -72,14 +72,14 @@ public struct OrderBy: FetchClause, QueryClause, DeleteClause, Hashable { /** The list of sort descriptors */ - public let sortDescriptors: [SortDescriptor] + public let sortDescriptors: [NSSortDescriptor] /** Initializes a `OrderBy` clause with an empty list of sort descriptors */ public init() { - self.init([SortDescriptor]()) + self.init([NSSortDescriptor]()) } /** @@ -87,7 +87,7 @@ public struct OrderBy: FetchClause, QueryClause, DeleteClause, Hashable { - parameter sortDescriptor: a `NSSortDescriptor` */ - public init(_ sortDescriptor: SortDescriptor) { + public init(_ sortDescriptor: NSSortDescriptor) { self.init([sortDescriptor]) } @@ -97,7 +97,7 @@ public struct OrderBy: FetchClause, QueryClause, DeleteClause, Hashable { - parameter sortDescriptors: a series of `NSSortDescriptor`s */ - public init(_ sortDescriptors: [SortDescriptor]) { + public init(_ sortDescriptors: [NSSortDescriptor]) { self.sortDescriptors = sortDescriptors } @@ -110,7 +110,7 @@ public struct OrderBy: FetchClause, QueryClause, DeleteClause, Hashable { public init(_ sortKey: [SortKey]) { self.init( - sortKey.map { sortKey -> SortDescriptor in + sortKey.map { sortKey -> NSSortDescriptor in switch sortKey { diff --git a/Sources/Fetching and Querying/Concrete Clauses/Select.swift b/Sources/Fetching and Querying/Concrete Clauses/Select.swift index df8018d..950f9f5 100644 --- a/Sources/Fetching and Querying/Concrete Clauses/Select.swift +++ b/Sources/Fetching and Querying/Concrete Clauses/Select.swift @@ -64,7 +64,7 @@ public protocol SelectAttributesResultType: SelectResultType { /** The `SelectTerm` is passed to the `Select` clause to indicate the attributes/aggregate keys to be queried. */ -public enum SelectTerm: StringLiteralConvertible, Hashable { +public enum SelectTerm: ExpressibleByStringLiteral, Hashable { /** Provides a `SelectTerm` to a `Select` clause for querying an entity attribute. A shorter way to do the same is to assign from the string keypath directly: @@ -223,7 +223,7 @@ public enum SelectTerm: StringLiteralConvertible, Hashable { } - // MARK: StringLiteralConvertible + // MARK: ExpressibleByStringLiteral public init(stringLiteral value: KeyPath) { @@ -367,7 +367,7 @@ public struct Select: Hashable { public var hashValue: Int { - return self.selectTerms.map { $0.hashValue }.reduce(0, combine: ^) + return self.selectTerms.map { $0.hashValue }.reduce(0, ^) } diff --git a/Sources/Fetching and Querying/Concrete Clauses/Tweak.swift b/Sources/Fetching and Querying/Concrete Clauses/Tweak.swift index d1eb6b4..340cdcd 100644 --- a/Sources/Fetching and Querying/Concrete Clauses/Tweak.swift +++ b/Sources/Fetching and Querying/Concrete Clauses/Tweak.swift @@ -47,7 +47,7 @@ public struct Tweak: FetchClause, QueryClause, DeleteClause { /** The block to customize the `NSFetchRequest` */ - public let closure: (fetchRequest: NSFetchRequest) -> Void + public let closure: (_ fetchRequest: NSFetchRequest) -> Void /** Initializes a `Tweak` clause with a closure where the `NSFetchRequest` may be configured. @@ -55,7 +55,7 @@ public struct Tweak: FetchClause, QueryClause, DeleteClause { - Important: `Tweak`'s closure is executed only just before the fetch occurs, so make sure that any values captured by the closure is not prone to race conditions. Also, some utilities (such as `ListMonitor`s) may keep `FetchClause`s in memory and may thus introduce retain cycles if reference captures are not handled properly. - parameter closure: the block to customize the `NSFetchRequest` */ - public init(_ closure: (fetchRequest: NSFetchRequest) -> Void) { + public init(_ closure: @escaping (_ fetchRequest: NSFetchRequest) -> Void) { self.closure = closure } @@ -65,6 +65,6 @@ public struct Tweak: FetchClause, QueryClause, DeleteClause { public func applyToFetchRequest(_ fetchRequest: NSFetchRequest) { - self.closure(fetchRequest: unsafeBitCast(fetchRequest, to: NSFetchRequest.self)) + self.closure(unsafeBitCast(fetchRequest, to: NSFetchRequest.self)) } } diff --git a/Sources/Fetching and Querying/Concrete Clauses/Where.swift b/Sources/Fetching and Querying/Concrete Clauses/Where.swift index 836bb37..eb075d2 100644 --- a/Sources/Fetching and Querying/Concrete Clauses/Where.swift +++ b/Sources/Fetching and Querying/Concrete Clauses/Where.swift @@ -29,17 +29,17 @@ import CoreData public func && (left: Where, right: Where) -> Where { - return Where(CompoundPredicate(type: .and, subpredicates: [left.predicate, right.predicate])) + return Where(NSCompoundPredicate(type: .and, subpredicates: [left.predicate, right.predicate])) } public func || (left: Where, right: Where) -> Where { - return Where(CompoundPredicate(type: .or, subpredicates: [left.predicate, right.predicate])) + return Where(NSCompoundPredicate(type: .or, subpredicates: [left.predicate, right.predicate])) } public prefix func ! (clause: Where) -> Where { - return Where(CompoundPredicate(type: .not, subpredicates: [clause.predicate])) + return Where(NSCompoundPredicate(type: .not, subpredicates: [clause.predicate])) } @@ -53,7 +53,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable { /** The `NSPredicate` for the fetch or query */ - public let predicate: Predicate + public let predicate: NSPredicate /** Initializes a `Where` clause with a predicate that always evaluates to `true` @@ -70,7 +70,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable { */ public init(_ value: Bool) { - self.init(Predicate(value: value)) + self.init(NSPredicate(value: value)) } /** @@ -81,7 +81,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable { */ public init(_ format: String, _ args: NSObject...) { - self.init(Predicate(format: format, argumentArray: args)) + self.init(NSPredicate(format: format, argumentArray: args)) } /** @@ -92,7 +92,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable { */ public init(_ format: String, argumentArray: [NSObject]?) { - self.init(Predicate(format: format, argumentArray: argumentArray)) + self.init(NSPredicate(format: format, argumentArray: argumentArray)) } /** @@ -104,8 +104,8 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable { public init(_ keyPath: KeyPath, isEqualTo value: NSObject?) { self.init(value == nil - ? Predicate(format: "\(keyPath) == nil") - : Predicate(format: "\(keyPath) == %@", argumentArray: [value!])) + ? NSPredicate(format: "\(keyPath) == nil") + : NSPredicate(format: "\(keyPath) == %@", argumentArray: [value!])) } /** @@ -116,7 +116,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable { */ public init(_ keyPath: KeyPath, isMemberOf list: [NSObject]) { - self.init(Predicate(format: "\(keyPath) IN %@", list)) + self.init(NSPredicate(format: "\(keyPath) IN %@", list)) } /** @@ -125,9 +125,9 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable { - parameter keyPath: the keyPath to compare with - parameter list: the sequence to check membership of */ - public init(_ keyPath: KeyPath, isMemberOf list: S) { + public init(_ keyPath: KeyPath, isMemberOf list: S) where S.Iterator.Element: NSObject { - self.init(Predicate(format: "\(keyPath) IN %@", Array(list) as NSArray)) + self.init(NSPredicate(format: "\(keyPath) IN %@", Array(list) as NSArray)) } /** @@ -135,7 +135,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable { - parameter predicate: the `NSPredicate` for the fetch or query */ - public init(_ predicate: Predicate) { + public init(_ predicate: NSPredicate) { self.predicate = predicate } diff --git a/Sources/Fetching and Querying/CoreStore+Querying.swift b/Sources/Fetching and Querying/CoreStore+Querying.swift index 08c5727..4cc04f9 100644 --- a/Sources/Fetching and Querying/CoreStore+Querying.swift +++ b/Sources/Fetching and Querying/CoreStore+Querying.swift @@ -59,7 +59,7 @@ public extension CoreStore { - parameter objects: an array of `NSManagedObject`s created/fetched outside the `DataStack` - returns: the `NSManagedObject` array for objects that exists in the `DataStack` */ - public static func fetchExisting(_ objects: S) -> [T] { + public static func fetchExisting(_ objects: S) -> [T] where S.Iterator.Element == T { return self.defaultStack.fetchExisting(objects) } @@ -70,7 +70,7 @@ public extension CoreStore { - parameter objectIDs: the `NSManagedObjectID` array for the objects - returns: the `NSManagedObject` array for objects that exists in the `DataStack` */ - public static func fetchExisting(_ objectIDs: S) -> [T] { + public static func fetchExisting(_ objectIDs: S) -> [T] where S.Iterator.Element == NSManagedObjectID { return self.defaultStack.fetchExisting(objectIDs) } diff --git a/Sources/Fetching and Querying/DataStack+Querying.swift b/Sources/Fetching and Querying/DataStack+Querying.swift index 5d8232b..8209029 100644 --- a/Sources/Fetching and Querying/DataStack+Querying.swift +++ b/Sources/Fetching and Querying/DataStack+Querying.swift @@ -25,9 +25,6 @@ import Foundation import CoreData -#if USE_FRAMEWORKS - import GCDKit -#endif // MARK: - DataStack @@ -76,7 +73,7 @@ public extension DataStack { - parameter objects: an array of `NSManagedObject`s created/fetched outside the `DataStack` - returns: the `NSManagedObject` array for objects that exists in the `DataStack` */ - public func fetchExisting(_ objects: S) -> [T] { + public func fetchExisting(_ objects: S) -> [T] where S.Iterator.Element == T { return objects.flatMap { (try? self.mainContext.existingObject(with: $0.objectID)) as? T } } @@ -87,7 +84,7 @@ public extension DataStack { - parameter objectIDs: the `NSManagedObjectID` array for the objects - returns: the `NSManagedObject` array for objects that exists in the `DataStack` */ - public func fetchExisting(_ objectIDs: S) -> [T] { + public func fetchExisting(_ objectIDs: S) -> [T] where S.Iterator.Element == NSManagedObjectID { return objectIDs.flatMap { (try? self.mainContext.existingObject(with: $0)) as? T } } diff --git a/Sources/Importing/BaseDataTransaction+Importing.swift b/Sources/Importing/BaseDataTransaction+Importing.swift index 2908488..a2dcd05 100644 --- a/Sources/Importing/BaseDataTransaction+Importing.swift +++ b/Sources/Importing/BaseDataTransaction+Importing.swift @@ -39,9 +39,9 @@ public extension BaseDataTransaction { - throws: an `ErrorType` thrown from any of the `ImportableObject` methods - returns: the created `ImportableObject` instance, or `nil` if the import was ignored */ - public func importObject( + public func importObject( _ into: Into, - source: T.ImportSource) throws -> T? { + source: T.ImportSource) throws -> T? where T: NSManagedObject, T: ImportableObject { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -68,9 +68,9 @@ public extension BaseDataTransaction { - parameter source: the object to import values from - throws: an `ErrorType` thrown from any of the `ImportableObject` methods */ - public func importObject( + public func importObject( _ object: T, - source: T.ImportSource) throws { + source: T.ImportSource) throws where T: NSManagedObject, T: ImportableObject { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -96,9 +96,9 @@ public extension BaseDataTransaction { - throws: an `ErrorType` thrown from any of the `ImportableObject` methods - returns: the array of created `ImportableObject` instances */ - public func importObjects( + public func importObjects( _ into: Into, - sourceArray: S) throws -> [T] { + sourceArray: S) throws -> [T] where T: NSManagedObject, T: ImportableObject, S.Iterator.Element == T.ImportSource { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -132,9 +132,9 @@ public extension BaseDataTransaction { - throws: an `ErrorType` thrown from any of the `ImportableUniqueObject` methods - returns: the created/updated `ImportableUniqueObject` instance, or `nil` if the import was ignored */ - public func importUniqueObject( + public func importUniqueObject( _ into: Into, - source: T.ImportSource) throws -> T? { + source: T.ImportSource) throws -> T? where T: NSManagedObject, T: ImportableUniqueObject { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -184,10 +184,10 @@ public extension BaseDataTransaction { - throws: an `ErrorType` thrown from any of the `ImportableUniqueObject` methods - returns: the array of created/updated `ImportableUniqueObject` instances */ - public func importUniqueObjects( + public func importUniqueObjects( _ into: Into, sourceArray: S, - preProcess: @noescape (mapping: [T.UniqueIDType: T.ImportSource]) throws -> [T.UniqueIDType: T.ImportSource] = { $0 }) throws -> [T] { + preProcess: @escaping (_ mapping: [T.UniqueIDType: T.ImportSource]) throws -> [T.UniqueIDType: T.ImportSource] = { $0 }) throws -> [T] where T: NSManagedObject, T: ImportableUniqueObject, S.Iterator.Element == T.ImportSource { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -211,7 +211,7 @@ public extension BaseDataTransaction { } } - mapping = try autoreleasepool { try preProcess(mapping: mapping) } + mapping = try autoreleasepool { try preProcess(mapping) } var objects = Dictionary() for object in self.fetchAll(From(), Where(T.uniqueIDKeyPath, isMemberOf: sortedIDs)) ?? [] { diff --git a/Sources/Internal/CoreStoreFetchedResultsController.swift b/Sources/Internal/CoreStoreFetchedResultsController.swift index bfbccc7..1d16bcb 100644 --- a/Sources/Internal/CoreStoreFetchedResultsController.swift +++ b/Sources/Internal/CoreStoreFetchedResultsController.swift @@ -36,7 +36,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll // MARK: Internal @nonobjc - internal convenience init(dataStack: DataStack, fetchRequest: NSFetchRequest, from: From? = nil, sectionBy: SectionBy? = nil, applyFetchClauses: (fetchRequest: NSFetchRequest) -> Void) { + internal convenience init(dataStack: DataStack, fetchRequest: NSFetchRequest, from: From? = nil, sectionBy: SectionBy? = nil, applyFetchClauses: (_ fetchRequest: NSFetchRequest) -> Void) { self.init( context: dataStack.mainContext, @@ -48,14 +48,14 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll } @nonobjc - internal init(context: NSManagedObjectContext, fetchRequest: NSFetchRequest, from: From? = nil, sectionBy: SectionBy? = nil, applyFetchClauses: (fetchRequest: NSFetchRequest) -> Void) { + internal init(context: NSManagedObjectContext, fetchRequest: NSFetchRequest, from: From? = nil, sectionBy: SectionBy? = nil, applyFetchClauses: (_ fetchRequest: NSFetchRequest) -> Void) { _ = from?.applyToFetchRequest( fetchRequest, context: context, applyAffectedStores: false ) - applyFetchClauses(fetchRequest: unsafeBitCast(fetchRequest, to: NSFetchRequest.self)) + applyFetchClauses(unsafeBitCast(fetchRequest, to: NSFetchRequest.self)) if let from = from { @@ -88,7 +88,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll @nonobjc internal func performFetchFromSpecifiedStores() throws { - if !self.reapplyAffectedStores(fetchRequest: self.fetchRequest, context: self.managedObjectContext) { + if !self.reapplyAffectedStores(self.fetchRequest, self.managedObjectContext) { CoreStore.log( .warning, @@ -113,7 +113,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll // MARK: Private @nonobjc - private let reapplyAffectedStores: (fetchRequest: NSFetchRequest, context: NSManagedObjectContext) -> Bool + private let reapplyAffectedStores: (_ fetchRequest: NSFetchRequest, _ context: NSManagedObjectContext) -> Bool } #endif diff --git a/Sources/Internal/DispatchQueue+CoreStore.swift b/Sources/Internal/DispatchQueue+CoreStore.swift new file mode 100644 index 0000000..dc675c6 --- /dev/null +++ b/Sources/Internal/DispatchQueue+CoreStore.swift @@ -0,0 +1,90 @@ +// +// DispatchQueue+CoreStore.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 + + +// MARK: - DispatchQueue + +internal extension DispatchQueue { + + internal convenience init(serialWith label: String) { + + self.init( + label: label, + qos: .default, + attributes: .allZeros, + autoreleaseFrequency: .inherit, + target: nil + ) + } + + internal convenience init(concurrentWith label: String) { + + self.init( + label: label, + qos: .default, + attributes: .concurrent, + autoreleaseFrequency: .inherit, + target: nil + ) + } + + internal func cs_isCurrentExecutionContext() -> Bool { + + let specific = ObjectIdentifier(self) + + self.setSpecific(key: Static.specificKey, value: specific) + return DispatchQueue.getSpecific(key: Static.specificKey) == specific + } + + internal func cs_sync(_ closure: () throws -> T) rethrows -> T { + + return self.sync { autoreleasepool(invoking: closure) } + } + + internal func cs_async(_ closure: () -> Void) { + + self.async { autoreleasepool(invoking: closure) } + } + + internal func cs_barrierSync(_ closure: () throws -> T) rethrows -> T { + + return self.sync(flags: .barrier) { autoreleasepool(invoking: closure) } + } + + internal func cs_barrierAsync(_ closure: () -> Void) { + + self.async(flags: .barrier) { autoreleasepool(invoking: closure) } + } + + + // MARK: Private + + private enum Static { + + static let specificKey = DispatchSpecificKey() + } +} diff --git a/Sources/Internal/Functions.swift b/Sources/Internal/Functions.swift index e54d435..695a581 100644 --- a/Sources/Internal/Functions.swift +++ b/Sources/Internal/Functions.swift @@ -27,7 +27,7 @@ import Foundation // MARK: Associated Objects -internal func cs_getAssociatedObjectForKey(_ key: UnsafePointer, inObject object: AnyObject) -> T? { +internal func cs_getAssociatedObjectForKey(_ key: UnsafeRawPointer, inObject object: AnyObject) -> T? { switch objc_getAssociatedObject(object, key) { @@ -42,17 +42,17 @@ internal func cs_getAssociatedObjectForKey(_ key: UnsafePointer(_ associatedObject: T?, forKey key: UnsafePointer, inObject object: AnyObject) { +internal func cs_setAssociatedRetainedObject(_ associatedObject: T?, forKey key: UnsafeRawPointer, inObject object: AnyObject) { objc_setAssociatedObject(object, key, associatedObject, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) } -internal func cs_setAssociatedCopiedObject(_ associatedObject: T?, forKey key: UnsafePointer, inObject object: AnyObject) { +internal func cs_setAssociatedCopiedObject(_ associatedObject: T?, forKey key: UnsafeRawPointer, inObject object: AnyObject) { objc_setAssociatedObject(object, key, associatedObject, .OBJC_ASSOCIATION_COPY_NONATOMIC) } -internal func cs_setAssociatedWeakObject(_ associatedObject: T?, forKey key: UnsafePointer, inObject object: AnyObject) { +internal func cs_setAssociatedWeakObject(_ associatedObject: T?, forKey key: UnsafeRawPointer, inObject object: AnyObject) { if let associatedObject = associatedObject { @@ -69,7 +69,7 @@ internal func cs_setAssociatedWeakObject(_ associatedObject: T?, f internal func cs_typeName(_ value: T) -> String { - return "'\(String(reflecting: value.dynamicType))'" + return "'\(String(reflecting: type(of: value)))'" } internal func cs_typeName(_ value: T.Type) -> String { diff --git a/Sources/Internal/NSManagedObjectContext+CoreStore.swift b/Sources/Internal/NSManagedObjectContext+CoreStore.swift index e704ba9..d461551 100644 --- a/Sources/Internal/NSManagedObjectContext+CoreStore.swift +++ b/Sources/Internal/NSManagedObjectContext+CoreStore.swift @@ -25,9 +25,6 @@ import Foundation import CoreData -#if USE_FRAMEWORKS - import GCDKit -#endif // MARK: - NSManagedObjectContext diff --git a/Sources/Internal/NSManagedObjectContext+Querying.swift b/Sources/Internal/NSManagedObjectContext+Querying.swift index 6dcb2cc..174f531 100644 --- a/Sources/Internal/NSManagedObjectContext+Querying.swift +++ b/Sources/Internal/NSManagedObjectContext+Querying.swift @@ -99,7 +99,7 @@ internal extension NSManagedObjectContext { internal func fetchOne(_ fetchRequest: NSFetchRequest) -> T? { var fetchResults: [T]? - var fetchError: ErrorProtocol? + var fetchError: Error? self.performAndWait { do { @@ -152,7 +152,7 @@ internal extension NSManagedObjectContext { internal func fetchAll(_ fetchRequest: NSFetchRequest) -> [T]? { var fetchResults: [T]? - var fetchError: ErrorProtocol? + var fetchError: Error? self.performAndWait { do { @@ -202,7 +202,7 @@ internal extension NSManagedObjectContext { internal func fetchCount(_ fetchRequest: NSFetchRequest) -> Int? { var count = 0 - var countError: ErrorProtocol? + var countError: Error? self.performAndWait { do { @@ -255,7 +255,7 @@ internal extension NSManagedObjectContext { internal func fetchObjectID(_ fetchRequest: NSFetchRequest) -> NSManagedObjectID? { var fetchResults: [NSManagedObjectID]? - var fetchError: ErrorProtocol? + var fetchError: Error? self.performAndWait { do { @@ -308,7 +308,7 @@ internal extension NSManagedObjectContext { internal func fetchObjectIDs(_ fetchRequest: NSFetchRequest) -> [NSManagedObjectID]? { var fetchResults: [NSManagedObjectID]? - var fetchError: ErrorProtocol? + var fetchError: Error? self.performAndWait { do { @@ -363,7 +363,7 @@ internal extension NSManagedObjectContext { internal func deleteAll(_ fetchRequest: NSFetchRequest) -> Int? { var numberOfDeletedObjects: Int? - var fetchError: ErrorProtocol? + var fetchError: Error? self.performAndWait { autoreleasepool { @@ -426,7 +426,7 @@ internal extension NSManagedObjectContext { internal func queryValue(_ selectTerms: [SelectTerm], fetchRequest: NSFetchRequest) -> U? { var fetchResults: [AnyObject]? - var fetchError: ErrorProtocol? + var fetchError: Error? self.performAndWait { do { @@ -459,7 +459,7 @@ internal extension NSManagedObjectContext { internal func queryValue(_ selectTerms: [SelectTerm], fetchRequest: NSFetchRequest) -> AnyObject? { var fetchResults: [AnyObject]? - var fetchError: ErrorProtocol? + var fetchError: Error? self.performAndWait { do { @@ -519,7 +519,7 @@ internal extension NSManagedObjectContext { internal func queryAttributes(_ fetchRequest: NSFetchRequest) -> [[NSString: AnyObject]]? { var fetchResults: [AnyObject]? - var fetchError: ErrorProtocol? + var fetchError: Error? self.performAndWait { do { diff --git a/Sources/Internal/NSManagedObjectContext+Transaction.swift b/Sources/Internal/NSManagedObjectContext+Transaction.swift index d8f0a75..1cf1f4f 100644 --- a/Sources/Internal/NSManagedObjectContext+Transaction.swift +++ b/Sources/Internal/NSManagedObjectContext+Transaction.swift @@ -25,9 +25,6 @@ import Foundation import CoreData -#if USE_FRAMEWORKS - import GCDKit -#endif // MARK: - NSManagedObjectContext @@ -150,13 +147,13 @@ internal extension NSManagedObjectContext { } @nonobjc - internal func saveAsynchronouslyWithCompletion(_ completion: ((result: SaveResult) -> Void) = { _ in }) { + internal func saveAsynchronouslyWithCompletion(_ completion: ((_ result: SaveResult) -> Void) = { _ in }) { self.perform { guard self.hasChanges else { - GCDQueue.main.async { + DispatchQueue.main.async { completion(result: SaveResult(hasChanges: false)) } @@ -176,7 +173,7 @@ internal extension NSManagedObjectContext { saveError, "Failed to save \(cs_typeName(NSManagedObjectContext.self))." ) - GCDQueue.main.async { + DispatchQueue.main.async { completion(result: SaveResult(saveError)) } @@ -189,7 +186,7 @@ internal extension NSManagedObjectContext { } else { - GCDQueue.main.async { + DispatchQueue.main.async { completion(result: SaveResult(hasChanges: true)) } diff --git a/Sources/Internal/NSManagedObjectModel+Setup.swift b/Sources/Internal/NSManagedObjectModel+Setup.swift index bc718c3..ab4dad9 100644 --- a/Sources/Internal/NSManagedObjectModel+Setup.swift +++ b/Sources/Internal/NSManagedObjectModel+Setup.swift @@ -36,7 +36,7 @@ internal extension NSManagedObjectModel { @nonobjc internal static func fromBundle(_ bundle: Bundle, modelName: String, modelVersionHints: Set = []) -> NSManagedObjectModel { - guard let modelFilePath = bundle.pathForResource(modelName, ofType: "momd") else { + guard let modelFilePath = bundle.path(forResource: modelName, ofType: "momd") else { CoreStore.abort("Could not find \"\(modelName).momd\" from the bundle. \(bundle)") } diff --git a/Sources/Internal/NSPersistentStoreCoordinator+Setup.swift b/Sources/Internal/NSPersistentStoreCoordinator+Setup.swift index 735af29..04e79b2 100644 --- a/Sources/Internal/NSPersistentStoreCoordinator+Setup.swift +++ b/Sources/Internal/NSPersistentStoreCoordinator+Setup.swift @@ -26,23 +26,19 @@ import Foundation import CoreData -#if USE_FRAMEWORKS - import GCDKit -#endif - // MARK: - NSPersistentStoreCoordinator internal extension NSPersistentStoreCoordinator { @nonobjc - internal func performAsynchronously(_ closure: () -> Void) { + internal func performAsynchronously(_ closure: @escaping () -> Void) { self.perform(closure) } @nonobjc - internal func performSynchronously(_ closure: () -> T) -> T { + internal func performSynchronously(_ closure: @escaping () -> T) -> T { var result: T? self.performAndWait { @@ -53,9 +49,9 @@ internal extension NSPersistentStoreCoordinator { } @nonobjc - internal func performSynchronously(_ closure: () throws -> T) throws -> T { + internal func performSynchronously(_ closure: @escaping () throws -> T) throws -> T { - var closureError: ErrorProtocol? + var closureError: Error? var result: T? self.performAndWait { diff --git a/Sources/Internal/NotificationObserver.swift b/Sources/Internal/NotificationObserver.swift index 1f57d49..227f43b 100644 --- a/Sources/Internal/NotificationObserver.swift +++ b/Sources/Internal/NotificationObserver.swift @@ -36,7 +36,7 @@ internal final class NotificationObserver { let object: AnyObject? let observer: NSObjectProtocol - init(notificationName: Notification.Name, object: AnyObject?, queue: OperationQueue? = nil, closure: (note: Notification) -> Void) { + init(notificationName: Notification.Name, object: AnyObject?, queue: OperationQueue? = nil, closure: @escaping (_ note: Notification) -> Void) { self.notificationName = notificationName self.object = object diff --git a/Sources/Logging/CoreStore+CustomDebugStringConvertible.swift b/Sources/Logging/CoreStore+CustomDebugStringConvertible.swift index 215b215..6ea23ec 100644 --- a/Sources/Logging/CoreStore+CustomDebugStringConvertible.swift +++ b/Sources/Logging/CoreStore+CustomDebugStringConvertible.swift @@ -912,7 +912,7 @@ private func formattedValue(_ any: Any) -> String { private func formattedDebugDescription(_ any: Any) -> String { - var string = "(\(String(reflecting: any.dynamicType))) " + var string = "(\(String(reflecting: type(of: any)))) " string.append(formattedValue(any)) return string } @@ -1163,7 +1163,7 @@ extension NSMappingModel: CoreStoreDebugStringConvertible { } } -extension Predicate: CoreStoreDebugStringConvertible { +extension NSPredicate: CoreStoreDebugStringConvertible { public var coreStoreDumpString: String { @@ -1199,7 +1199,7 @@ extension NSRelationshipDescription: CoreStoreDebugStringConvertible { } } -extension SortDescriptor: CoreStoreDebugStringConvertible { +extension NSSortDescriptor: CoreStoreDebugStringConvertible { public var coreStoreDumpString: String { diff --git a/Sources/Logging/CoreStore+Logging.swift b/Sources/Logging/CoreStore+Logging.swift index e62fe71..dfb5ed2 100644 --- a/Sources/Logging/CoreStore+Logging.swift +++ b/Sources/Logging/CoreStore+Logging.swift @@ -71,8 +71,8 @@ public extension CoreStore { ) } - @noreturn - internal static func abort(_ message: String, fileName: StaticString = #file, lineNumber: Int = #line, functionName: StaticString = #function) { + + internal static func abort(_ message: String, fileName: StaticString = #file, lineNumber: Int = #line, functionName: StaticString = #function) -> Never { self.logger.abort( message, diff --git a/Sources/Migrating/CoreStore+Migration.swift b/Sources/Migrating/CoreStore+Migration.swift index c716c6a..06b5dc5 100644 --- a/Sources/Migrating/CoreStore+Migration.swift +++ b/Sources/Migrating/CoreStore+Migration.swift @@ -25,9 +25,6 @@ import Foundation import CoreData -#if USE_FRAMEWORKS - import GCDKit -#endif // MARK: - CoreStore @@ -50,7 +47,7 @@ public extension CoreStore { - parameter storeType: the storage type - parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `StorageInterface` associated to the `SetupResult.success` may not always be the same instance as the parameter argument if a previous `StorageInterface` was already added at the same URL and with the same configuration. */ - public static func addStorage(_ storeType: T.Type, completion: (SetupResult) -> Void) { + public static func addStorage(_ storeType: T.Type, completion: (SetupResult) -> Void) where T: DefaultInitializableStore { self.defaultStack.addStorage(storeType.init(), completion: completion) } @@ -93,7 +90,7 @@ public extension CoreStore { - parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `LocalStorage` associated to the `SetupResult.success` may not always be the same instance as the parameter argument if a previous `LocalStorage` was already added at the same URL and with the same configuration. - returns: an `NSProgress` instance if a migration has started, or `nil` if either no migrations are required or if a failure occured. */ - public static func addStorage(_ storeType: T.Type, completion: (SetupResult) -> Void) -> Progress? { + public static func addStorage(_ storeType: T.Type, completion: (SetupResult) -> Void) -> Progress? where T: DefaultInitializableStore { return self.defaultStack.addStorage(storeType.init(), completion: completion) } diff --git a/Sources/Migrating/DataStack+Migration.swift b/Sources/Migrating/DataStack+Migration.swift index e9ae607..221dc81 100644 --- a/Sources/Migrating/DataStack+Migration.swift +++ b/Sources/Migrating/DataStack+Migration.swift @@ -25,9 +25,6 @@ import Foundation import CoreData -#if USE_FRAMEWORKS - import GCDKit -#endif // MARK: - DataStack @@ -50,7 +47,7 @@ public extension DataStack { - parameter storeType: the storage type - parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `StorageInterface` associated to the `SetupResult.success` may not always be the same instance as the parameter argument if a previous `StorageInterface` was already added at the same URL and with the same configuration. */ - public func addStorage(_ storeType: T.Type, completion: (SetupResult) -> Void) { + public func addStorage(_ storeType: T.Type, completion: (SetupResult) -> Void) where T: DefaultInitializableStore { self.addStorage(storeType.init(), completion: completion) } @@ -71,13 +68,13 @@ public extension DataStack { - parameter storage: the storage - parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `StorageInterface` associated to the `SetupResult.success` may not always be the same instance as the parameter argument if a previous `StorageInterface` was already added at the same URL and with the same configuration. */ - public func addStorage(_ storage: T, completion: (SetupResult) -> Void) { + public func addStorage(_ storage: T, completion: @escaping (SetupResult) -> Void) { self.coordinator.performAsynchronously { if let _ = self.persistentStoreForStorage(storage) { - GCDQueue.main.async { + DispatchQueue.main.async { completion(SetupResult(storage)) } @@ -92,7 +89,7 @@ public extension DataStack { finalStoreOptions: storage.storeOptions ) - GCDQueue.main.async { + DispatchQueue.main.async { completion(SetupResult(storage)) } @@ -104,7 +101,7 @@ public extension DataStack { storeError, "Failed to add \(cs_typeName(storage)) to the stack." ) - GCDQueue.main.async { + DispatchQueue.main.async { completion(SetupResult(storeError)) } @@ -129,9 +126,9 @@ public extension DataStack { - parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `LocalStorage` associated to the `SetupResult.success` may not always be the same instance as the parameter argument if a previous `LocalStorage` was already added at the same URL and with the same configuration. - returns: an `NSProgress` instance if a migration has started, or `nil` if either no migrations are required or if a failure occured. */ - public func addStorage(_ storeType: T.Type, completion: (SetupResult) -> Void) -> Progress? { + public func addStorage(_ storeType: T.Type, completion: (SetupResult) -> Void) -> Progress? where T: DefaultInitializableStore { - return self.addStorage(storeType.init(), completion: completion) + return self.addStorage(storeType.init() as! T.Type, completion: completion) } /** @@ -151,7 +148,7 @@ public extension DataStack { - parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `LocalStorage` associated to the `SetupResult.success` may not always be the same instance as the parameter argument if a previous `LocalStorage` was already added at the same URL and with the same configuration. - returns: an `NSProgress` instance if a migration has started, or `nil` if either no migrations are required or if a failure occured. */ - public func addStorage(_ storage: T, completion: (SetupResult) -> Void) -> Progress? { + public func addStorage(_ storage: T, completion: @escaping (SetupResult) -> Void) -> Progress? { let fileURL = storage.fileURL CoreStore.assert( @@ -163,7 +160,7 @@ public extension DataStack { if let _ = self.persistentStoreForStorage(storage) { - GCDQueue.main.async { + DispatchQueue.main.async { completion(SetupResult(storage)) } @@ -175,7 +172,7 @@ public extension DataStack { if let existingStorage = persistentStore.storageInterface as? T, storage.matchesPersistentStore(persistentStore) { - GCDQueue.main.async { + DispatchQueue.main.async { completion(SetupResult(existingStorage)) } @@ -187,7 +184,7 @@ public extension DataStack { error, "Failed to add \(cs_typeName(storage)) at \"\(fileURL)\" because a different \(cs_typeName(NSPersistentStore.self)) at that URL already exists." ) - GCDQueue.main.async { + DispatchQueue.main.async { completion(SetupResult(error)) } @@ -203,14 +200,14 @@ public extension DataStack { ) let metadata = try NSPersistentStoreCoordinator.metadataForPersistentStore( - ofType: storage.dynamicType.storeType, + ofType: type(of: storage).storeType, at: fileURL as URL, options: storage.storeOptions ) return self.upgradeStorageIfNeeded( storage, - metadata: metadata, + metadata: metadata as [String : AnyObject], completion: { (result) -> Void in if case .failure(.internalError(let error)) = result { @@ -222,7 +219,7 @@ public extension DataStack { _ = try self.model[metadata].flatMap(storage.eraseStorageAndWait) _ = try self.addStorageAndWait(storage) - GCDQueue.main.async { + DispatchQueue.main.async { completion(SetupResult(storage)) } @@ -258,14 +255,14 @@ public extension DataStack { _ = try self.addStorageAndWait(storage) - GCDQueue.main.async { + DispatchQueue.main.async { completion(SetupResult(storage)) } } catch { - GCDQueue.main.async { + DispatchQueue.main.async { completion(SetupResult(error)) } @@ -279,7 +276,7 @@ public extension DataStack { storeError, "Failed to load SQLite \(cs_typeName(NSPersistentStore.self)) metadata." ) - GCDQueue.main.async { + DispatchQueue.main.async { completion(SetupResult(storeError)) } @@ -315,14 +312,14 @@ public extension DataStack { - parameter storage: the cloud storage - parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `CloudStorage` associated to the `SetupResult.success` may not always be the same instance as the parameter argument if a previous `CloudStorage` was already added at the same URL and with the same configuration. */ - public func addStorage(_ storage: T, completion: (SetupResult) -> Void) { + public func addStorage(_ storage: T, completion: @escaping (SetupResult) -> Void) { let cacheFileURL = storage.cacheFileURL self.coordinator.performSynchronously { if let _ = self.persistentStoreForStorage(storage) { - GCDQueue.main.async { + DispatchQueue.main.async { completion(SetupResult(storage)) } @@ -334,7 +331,7 @@ public extension DataStack { if let existingStorage = persistentStore.storageInterface as? T, storage.matchesPersistentStore(persistentStore) { - GCDQueue.main.async { + DispatchQueue.main.async { completion(SetupResult(existingStorage)) } @@ -346,7 +343,7 @@ public extension DataStack { error, "Failed to add \(cs_typeName(storage)) at \"\(cacheFileURL)\" because a different \(cs_typeName(NSPersistentStore.self)) at that URL already exists." ) - GCDQueue.main.async { + DispatchQueue.main.async { completion(SetupResult(error)) } @@ -371,7 +368,7 @@ public extension DataStack { finalURL: cacheFileURL, finalStoreOptions: storeOptions ) - GCDQueue.main.async { + DispatchQueue.main.async { completion(SetupResult(storage)) } @@ -379,7 +376,7 @@ public extension DataStack { catch let error as NSError where storage.cloudStorageOptions.contains(.recreateLocalStoreOnModelMismatch) && error.isCoreDataMigrationError { let metadata = try NSPersistentStoreCoordinator.metadataForPersistentStore( - ofType: storage.dynamicType.storeType, + ofType: type(of: storage).storeType, at: cacheFileURL, options: storeOptions ) @@ -398,14 +395,14 @@ public extension DataStack { _ = try self.addStorageAndWait(storage) - GCDQueue.main.async { + DispatchQueue.main.async { completion(SetupResult(storage)) } } catch { - GCDQueue.main.async { + DispatchQueue.main.async { completion(SetupResult(error)) } @@ -418,7 +415,7 @@ public extension DataStack { storeError, "Failed to load \(cs_typeName(NSPersistentStore.self)) metadata." ) - GCDQueue.main.async { + DispatchQueue.main.async { completion(SetupResult(storeError)) } @@ -447,13 +444,13 @@ public extension DataStack { ) let metadata = try NSPersistentStoreCoordinator.metadataForPersistentStore( - ofType: storage.dynamicType.storeType, + ofType: type(of: storage).storeType, at: fileURL as URL, options: storage.storeOptions ) return self.upgradeStorageIfNeeded( storage, - metadata: metadata, + metadata: metadata as [String : AnyObject], completion: completion ) } @@ -489,12 +486,12 @@ public extension DataStack { do { let metadata = try NSPersistentStoreCoordinator.metadataForPersistentStore( - ofType: storage.dynamicType.storeType, + ofType: type(of: storage).storeType, at: fileURL as URL, options: storage.storeOptions ) - guard let migrationSteps = self.computeMigrationFromStorage(storage, metadata: metadata) else { + guard let migrationSteps = self.computeMigrationFromStorage(storage, metadata: metadata as [String : AnyObject]) else { let error = CoreStoreError.mappingModelNotFound( localStoreURL: fileURL, @@ -540,7 +537,7 @@ public extension DataStack { // MARK: Private - private func upgradeStorageIfNeeded(_ storage: T, metadata: [String: AnyObject], completion: (MigrationResult) -> Void) -> Progress? { + private func upgradeStorageIfNeeded(_ storage: T, metadata: [String: AnyObject], completion: @escaping (MigrationResult) -> Void) -> Progress? { guard let migrationSteps = self.computeMigrationFromStorage(storage, metadata: metadata) else { @@ -554,7 +551,7 @@ public extension DataStack { "Failed to find migration steps from \(cs_typeName(storage)) at URL \"\(storage.fileURL)\" to version model \"\(self.model)\"." ) - GCDQueue.main.async { + DispatchQueue.main.async { completion(MigrationResult(error)) } @@ -564,7 +561,7 @@ public extension DataStack { let numberOfMigrations: Int64 = Int64(migrationSteps.count) if numberOfMigrations == 0 { - GCDQueue.main.async { + DispatchQueue.main.async { completion(MigrationResult([])) return @@ -578,7 +575,7 @@ public extension DataStack { error, "Failed to find migration mapping from the \(cs_typeName(storage)) at URL \"\(storage.fileURL)\" to version model \"\(self.modelVersion)\" without requiring progessive migrations." ) - GCDQueue.main.async { + DispatchQueue.main.async { completion(MigrationResult(error)) } @@ -627,7 +624,7 @@ public extension DataStack { } } - GCDQueue.main.async { + DispatchQueue.main.async { _ = withExtendedLifetime(childProgress) { (_: Progress) -> Void in } } @@ -642,7 +639,7 @@ public extension DataStack { operations.forEach { migrationOperation.addDependency($0) } migrationOperation.addExecutionBlock { () -> Void in - GCDQueue.main.async { + DispatchQueue.main.async { progress.setProgressHandler(nil) completion(migrationResult ?? MigrationResult(migrationTypes)) @@ -752,7 +749,7 @@ public extension DataStack { ) let temporaryFileURL = try! temporaryDirectoryURL.appendingPathComponent( - fileURL.lastPathComponent!, + fileURL.lastPathComponent, isDirectory: false ) @@ -766,11 +763,11 @@ public extension DataStack { try migrationManager.migrateStore( from: fileURL, - sourceType: storage.dynamicType.storeType, + sourceType: type(of: storage).storeType, options: nil, with: mappingModel, toDestinationURL: temporaryFileURL, - destinationType: storage.dynamicType.storeType, + destinationType: type(of: storage).storeType, destinationOptions: nil ) } diff --git a/Sources/Migrating/MigrationChain.swift b/Sources/Migrating/MigrationChain.swift index 3b71a9a..b0ae79b 100644 --- a/Sources/Migrating/MigrationChain.swift +++ b/Sources/Migrating/MigrationChain.swift @@ -60,7 +60,7 @@ import CoreData - a version appears twice as a key in a dictionary literal - a loop is found in any of the paths */ -public struct MigrationChain: NilLiteralConvertible, StringLiteralConvertible, DictionaryLiteralConvertible, ArrayLiteralConvertible, Equatable { +public struct MigrationChain: ExpressibleByNilLiteral, ExpressibleByStringLiteral, ExpressibleByDictionaryLiteral, ExpressibleByArrayLiteral, Equatable { /** Initializes the `MigrationChain` with empty values, which instructs the `DataStack` to use the .xcdatamodel's current version as the final version, and to disable progressive migrations. @@ -87,7 +87,7 @@ public struct MigrationChain: NilLiteralConvertible, StringLiteralConvertible, D /** Initializes the `MigrationChain` with a linear order of versions, which becomes the order of the `DataStack`'s progressive migrations. */ - public init(_ elements: T) { + public init(_ elements: T) where T.Iterator.Element == String, T.SubSequence.Iterator.Element == String, T.Index: Comparable { CoreStore.assert(Set(elements).count == Array(elements).count, "\(cs_typeName(MigrationChain.self))'s migration chain could not be created due to duplicate version strings.") @@ -168,7 +168,7 @@ public struct MigrationChain: NilLiteralConvertible, StringLiteralConvertible, D } - // MARK: NilLiteralConvertible + // MARK: ExpressibleByNilLiteral public init(nilLiteral: ()) { @@ -176,7 +176,7 @@ public struct MigrationChain: NilLiteralConvertible, StringLiteralConvertible, D } - // MARK: StringLiteralConvertible + // MARK: ExpressibleByStringLiteral public init(stringLiteral value: String) { @@ -200,7 +200,7 @@ public struct MigrationChain: NilLiteralConvertible, StringLiteralConvertible, D } - // MARK: DictionaryLiteralConvertible + // MARK: ExpressibleByDictionaryLiteral public init(dictionaryLiteral elements: (String, String)...) { @@ -208,7 +208,7 @@ public struct MigrationChain: NilLiteralConvertible, StringLiteralConvertible, D } - // MARK: ArrayLiteralConvertible + // MARK: ExpressibleByArrayLiteral public init(arrayLiteral elements: String...) { diff --git a/Sources/Migrating/MigrationResult.swift b/Sources/Migrating/MigrationResult.swift index b3506ba..7471909 100644 --- a/Sources/Migrating/MigrationResult.swift +++ b/Sources/Migrating/MigrationResult.swift @@ -57,7 +57,7 @@ import Foundation } ``` */ -public enum MigrationResult: Boolean, Hashable { +public enum MigrationResult: Hashable { /** `MigrationResult.success` indicates either the migration succeeded, or there were no migrations needed. The associated value is an array of `MigrationType`s reflecting the migration steps completed. @@ -70,9 +70,10 @@ public enum MigrationResult: Boolean, Hashable { case failure(CoreStoreError) - // MARK: BooleanType - - public var boolValue: Bool { + /** + Returns `true` if the result indicates `.success`, `false` if the result is `.failure`. + */ + public var isSuccess: Bool { switch self { @@ -90,7 +91,7 @@ public enum MigrationResult: Boolean, Hashable { case .success(let migrationTypes): return self.boolValue.hashValue - ^ migrationTypes.map { $0.hashValue }.reduce(0, combine: ^).hashValue + ^ migrationTypes.map { $0.hashValue }.reduce(0, ^).hashValue case .failure(let error): return self.boolValue.hashValue ^ error.hashValue @@ -110,7 +111,7 @@ public enum MigrationResult: Boolean, Hashable { self = .failure(error) } - internal init(_ error: ErrorProtocol) { + internal init(_ error: Error) { self = .failure(CoreStoreError(error)) } diff --git a/Sources/Migrating/MigrationType.swift b/Sources/Migrating/MigrationType.swift index 833ed85..fe4ae85 100644 --- a/Sources/Migrating/MigrationType.swift +++ b/Sources/Migrating/MigrationType.swift @@ -31,7 +31,7 @@ import Foundation /** The `MigrationType` specifies the type of migration required for a store. */ -public enum MigrationType: Boolean, Hashable { +public enum MigrationType: Hashable { /** Indicates that the persistent store matches the latest model version and no migration is needed @@ -108,10 +108,10 @@ public enum MigrationType: Boolean, Hashable { return false } - - // MARK: BooleanType - - public var boolValue: Bool { + /** + Returns `true` if the `MigrationType` is either a lightweight or a heavyweight migration. Returns `false` if no migrations specified. + */ + public var hasMigration: Bool { switch self { diff --git a/Sources/Migrating/SetupResult.swift b/Sources/Migrating/SetupResult.swift index 77cbae2..dad3c86 100644 --- a/Sources/Migrating/SetupResult.swift +++ b/Sources/Migrating/SetupResult.swift @@ -60,7 +60,7 @@ import CoreData ) ``` */ -public enum SetupResult: Boolean, Hashable { +public enum SetupResult: Hashable { /** `SetupResult.success` indicates that the storage setup succeeded. The associated object for this `enum` value is the related `StorageInterface` instance. @@ -73,9 +73,10 @@ public enum SetupResult: Boolean, Hashable { case failure(CoreStoreError) - // MARK: BooleanType - - public var boolValue: Bool { + /** + Returns `true` if the result indicates `.success`, `false` if the result is `.failure`. + */ + public var isSuccess: Bool { switch self { @@ -112,7 +113,7 @@ public enum SetupResult: Boolean, Hashable { self = .failure(error) } - internal init(_ error: ErrorProtocol) { + internal init(_ error: Error) { self = .failure(CoreStoreError(error)) } diff --git a/Sources/ObjectiveC/CSAsynchronousDataTransaction.swift b/Sources/ObjectiveC/CSAsynchronousDataTransaction.swift index 70b06c3..a443491 100644 --- a/Sources/ObjectiveC/CSAsynchronousDataTransaction.swift +++ b/Sources/ObjectiveC/CSAsynchronousDataTransaction.swift @@ -43,11 +43,11 @@ public final class CSAsynchronousDataTransaction: CSBaseDataTransaction { - parameter completion: the block executed after the save completes. Success or failure is reported by the `CSSaveResult` argument of the block. */ @objc - public func commitWithCompletion(_ completion: ((result: CSSaveResult) -> Void)?) { + public func commitWithCompletion(_ completion: ((_ result: CSSaveResult) -> Void)?) { self.bridgeToSwift.commit { (result) in - completion?(result: result.bridgeToObjectiveC) + completion?(result.bridgeToObjectiveC) } } @@ -59,7 +59,7 @@ public final class CSAsynchronousDataTransaction: CSBaseDataTransaction { */ @objc @discardableResult - public func beginSynchronous(_ closure: (transaction: CSSynchronousDataTransaction) -> Void) -> CSSaveResult? { + public func beginSynchronous(_ closure: @escaping (_ transaction: CSSynchronousDataTransaction) -> Void) -> CSSaveResult? { return bridge { @@ -75,7 +75,7 @@ public final class CSAsynchronousDataTransaction: CSBaseDataTransaction { public override var description: String { - return "(\(String(reflecting: self.dynamicType))) \(self.bridgeToSwift.coreStoreDumpString)" + return "(\(String(reflecting: type(of: self)))) \(self.bridgeToSwift.coreStoreDumpString)" } diff --git a/Sources/ObjectiveC/CSBaseDataTransaction.swift b/Sources/ObjectiveC/CSBaseDataTransaction.swift index 808c603..a95143b 100644 --- a/Sources/ObjectiveC/CSBaseDataTransaction.swift +++ b/Sources/ObjectiveC/CSBaseDataTransaction.swift @@ -266,7 +266,7 @@ public class CSBaseDataTransaction: NSObject, CoreStoreObjectiveCType { return ObjectIdentifier(self.bridgeToSwift).hashValue } - public override func isEqual(_ object: AnyObject?) -> Bool { + public override func isEqual(_ object: Any?) -> Bool { guard let object = object as? CSBaseDataTransaction else { diff --git a/Sources/ObjectiveC/CSCoreStore+Transaction.swift b/Sources/ObjectiveC/CSCoreStore+Transaction.swift index 43e037f..6e5ad35 100644 --- a/Sources/ObjectiveC/CSCoreStore+Transaction.swift +++ b/Sources/ObjectiveC/CSCoreStore+Transaction.swift @@ -36,11 +36,11 @@ public extension CSCoreStore { - parameter closure: the block where creates, updates, and deletes can be made to the transaction. Transaction blocks are executed serially in a background queue, and all changes are made from a concurrent `NSManagedObjectContext`. */ @objc - public static func beginAsynchronous(_ closure: (transaction: CSAsynchronousDataTransaction) -> Void) { + public static func beginAsynchronous(_ closure: @escaping (_ transaction: CSAsynchronousDataTransaction) -> Void) { return CoreStore.beginAsynchronous { (transaction) in - closure(transaction: transaction.bridgeToObjectiveC) + closure(transaction.bridgeToObjectiveC) } } @@ -52,7 +52,7 @@ public extension CSCoreStore { */ @objc @discardableResult - public static func beginSynchronous(_ closure: (transaction: CSSynchronousDataTransaction) -> Void) -> CSSaveResult? { + public static func beginSynchronous(_ closure: @escaping (_ transaction: CSSynchronousDataTransaction) -> Void) -> CSSaveResult? { return bridge { diff --git a/Sources/ObjectiveC/CSDataStack+Transaction.swift b/Sources/ObjectiveC/CSDataStack+Transaction.swift index d9f7f5d..41e55be 100644 --- a/Sources/ObjectiveC/CSDataStack+Transaction.swift +++ b/Sources/ObjectiveC/CSDataStack+Transaction.swift @@ -36,11 +36,11 @@ public extension CSDataStack { - parameter closure: the block where creates, updates, and deletes can be made to the transaction. Transaction blocks are executed serially in a background queue, and all changes are made from a concurrent `NSManagedObjectContext`. */ @objc - public func beginAsynchronous(_ closure: (transaction: CSAsynchronousDataTransaction) -> Void) { + public func beginAsynchronous(_ closure: @escaping (_ transaction: CSAsynchronousDataTransaction) -> Void) { return self.bridgeToSwift.beginAsynchronous { (transaction) in - closure(transaction: transaction.bridgeToObjectiveC) + closure(transaction.bridgeToObjectiveC) } } @@ -52,7 +52,7 @@ public extension CSDataStack { */ @objc @discardableResult - public func beginSynchronous(_ closure: (transaction: CSSynchronousDataTransaction) -> Void) -> CSSaveResult? { + public func beginSynchronous(_ closure: @escaping (_ transaction: CSSynchronousDataTransaction) -> Void) -> CSSaveResult? { return bridge { diff --git a/Sources/ObjectiveC/CSDataStack.swift b/Sources/ObjectiveC/CSDataStack.swift index ee5c380..4965144 100644 --- a/Sources/ObjectiveC/CSDataStack.swift +++ b/Sources/ObjectiveC/CSDataStack.swift @@ -244,7 +244,7 @@ public final class CSDataStack: NSObject, CoreStoreObjectiveCType { return ObjectIdentifier(self.bridgeToSwift).hashValue } - public override func isEqual(_ object: AnyObject?) -> Bool { + public override func isEqual(_ object: Any?) -> Bool { guard let object = object as? CSDataStack else { @@ -255,7 +255,7 @@ public final class CSDataStack: NSObject, CoreStoreObjectiveCType { public override var description: String { - return "(\(String(reflecting: self.dynamicType))) \(self.bridgeToSwift.coreStoreDumpString)" + return "(\(String(reflecting: type(of: self)))) \(self.bridgeToSwift.coreStoreDumpString)" } diff --git a/Sources/ObjectiveC/CSError.swift b/Sources/ObjectiveC/CSError.swift index 6caf96f..f96f45f 100644 --- a/Sources/ObjectiveC/CSError.swift +++ b/Sources/ObjectiveC/CSError.swift @@ -53,7 +53,7 @@ public final class CSError: NSError, CoreStoreObjectiveCType { return self.bridgeToSwift.hashValue } - public override func isEqual(_ object: AnyObject?) -> Bool { + public override func isEqual(_ object: Any?) -> Bool { guard let object = object as? CSError else { @@ -64,7 +64,7 @@ public final class CSError: NSError, CoreStoreObjectiveCType { public override var description: String { - return "(\(String(reflecting: self.dynamicType))) \(self.bridgeToSwift.coreStoreDumpString)" + return "(\(String(reflecting: type(of: self)))) \(self.bridgeToSwift.coreStoreDumpString)" } @@ -150,27 +150,27 @@ public final class CSError: NSError, CoreStoreObjectiveCType { case .differentStorageExistsAtURL(let existingPersistentStoreURL): code = .differentStorageExistsAtURL info = [ - "existingPersistentStoreURL": existingPersistentStoreURL + "existingPersistentStoreURL" as NSObject: existingPersistentStoreURL as AnyObject ] case .mappingModelNotFound(let localStoreURL, let targetModel, let targetModelVersion): code = .mappingModelNotFound info = [ - "localStoreURL": localStoreURL, - "targetModel": targetModel, - "targetModelVersion": targetModelVersion + "localStoreURL" as NSObject: localStoreURL as AnyObject, + "targetModel" as NSObject: targetModel, + "targetModelVersion" as NSObject: targetModelVersion as AnyObject ] case .progressiveMigrationRequired(let localStoreURL): code = .progressiveMigrationRequired info = [ - "localStoreURL": localStoreURL + "localStoreURL" as NSObject: localStoreURL as AnyObject ] case .internalError(let NSError): code = .internalError info = [ - "NSError": NSError + "NSError" as NSObject: NSError ] } @@ -242,7 +242,7 @@ extension CoreStoreError: CoreStoreSwiftType { // MARK: Internal -internal extension ErrorProtocol { +internal extension Error { internal var bridgeToSwift: CoreStoreError { @@ -254,7 +254,7 @@ internal extension ErrorProtocol { case let error as CSError: return error.bridgeToSwift - case let error as NSError where self.dynamicType is NSError.Type: + case let error as NSError where type(of: self) is NSError.Type: return .internalError(NSError: error) default: diff --git a/Sources/ObjectiveC/CSFrom.swift b/Sources/ObjectiveC/CSFrom.swift index 7354b76..bd33df0 100644 --- a/Sources/ObjectiveC/CSFrom.swift +++ b/Sources/ObjectiveC/CSFrom.swift @@ -136,7 +136,7 @@ public final class CSFrom: NSObject, CoreStoreObjectiveCType { public override var description: String { - return "(\(String(reflecting: self.dynamicType))) \(self.bridgeToSwift.coreStoreDumpString)" + return "(\(String(reflecting: type(of: self)))) \(self.bridgeToSwift.coreStoreDumpString)" } diff --git a/Sources/ObjectiveC/CSGroupBy.swift b/Sources/ObjectiveC/CSGroupBy.swift index 69c37c1..2c1eaf0 100644 --- a/Sources/ObjectiveC/CSGroupBy.swift +++ b/Sources/ObjectiveC/CSGroupBy.swift @@ -76,7 +76,7 @@ public final class CSGroupBy: NSObject, CSQueryClause, CoreStoreObjectiveCType { return self.bridgeToSwift.hashValue } - public override func isEqual(_ object: AnyObject?) -> Bool { + public override func isEqual(_ object: Any?) -> Bool { guard let object = object as? CSGroupBy else { @@ -87,7 +87,7 @@ public final class CSGroupBy: NSObject, CSQueryClause, CoreStoreObjectiveCType { public override var description: String { - return "(\(String(reflecting: self.dynamicType))) \(self.bridgeToSwift.coreStoreDumpString)" + return "(\(String(reflecting: type(of: self)))) \(self.bridgeToSwift.coreStoreDumpString)" } diff --git a/Sources/ObjectiveC/CSInMemoryStore.swift b/Sources/ObjectiveC/CSInMemoryStore.swift index 4145437..b04f900 100644 --- a/Sources/ObjectiveC/CSInMemoryStore.swift +++ b/Sources/ObjectiveC/CSInMemoryStore.swift @@ -92,7 +92,7 @@ public final class CSInMemoryStore: NSObject, CSStorageInterface, CoreStoreObjec return ObjectIdentifier(self.bridgeToSwift).hashValue } - public override func isEqual(_ object: AnyObject?) -> Bool { + public override func isEqual(_ object: Any?) -> Bool { guard let object = object as? CSInMemoryStore else { @@ -103,7 +103,7 @@ public final class CSInMemoryStore: NSObject, CSStorageInterface, CoreStoreObjec public override var description: String { - return "(\(String(reflecting: self.dynamicType))) \(self.bridgeToSwift.coreStoreDumpString)" + return "(\(String(reflecting: type(of: self)))) \(self.bridgeToSwift.coreStoreDumpString)" } diff --git a/Sources/ObjectiveC/CSInto.swift b/Sources/ObjectiveC/CSInto.swift index e85cd81..080ee04 100644 --- a/Sources/ObjectiveC/CSInto.swift +++ b/Sources/ObjectiveC/CSInto.swift @@ -93,7 +93,7 @@ public final class CSInto: NSObject, CoreStoreObjectiveCType { return self.bridgeToSwift.hashValue } - public override func isEqual(_ object: AnyObject?) -> Bool { + public override func isEqual(_ object: Any?) -> Bool { guard let object = object as? CSInto else { @@ -104,7 +104,7 @@ public final class CSInto: NSObject, CoreStoreObjectiveCType { public override var description: String { - return "(\(String(reflecting: self.dynamicType))) \(self.bridgeToSwift.coreStoreDumpString)" + return "(\(String(reflecting: type(of: self)))) \(self.bridgeToSwift.coreStoreDumpString)" } diff --git a/Sources/ObjectiveC/CSListMonitor.swift b/Sources/ObjectiveC/CSListMonitor.swift index 391db0c..f166101 100644 --- a/Sources/ObjectiveC/CSListMonitor.swift +++ b/Sources/ObjectiveC/CSListMonitor.swift @@ -513,7 +513,7 @@ public final class CSListMonitor: NSObject, CoreStoreObjectiveCType { return self.bridgeToSwift.hashValue } - public override func isEqual(_ object: AnyObject?) -> Bool { + public override func isEqual(_ object: Any?) -> Bool { guard let object = object as? CSListMonitor else { @@ -524,7 +524,7 @@ public final class CSListMonitor: NSObject, CoreStoreObjectiveCType { public override var description: String { - return "(\(String(reflecting: self.dynamicType))) \(self.bridgeToSwift.coreStoreDumpString)" + return "(\(String(reflecting: type(of: self)))) \(self.bridgeToSwift.coreStoreDumpString)" } diff --git a/Sources/ObjectiveC/CSMigrationResult.swift b/Sources/ObjectiveC/CSMigrationResult.swift index 6c29313..9e69257 100644 --- a/Sources/ObjectiveC/CSMigrationResult.swift +++ b/Sources/ObjectiveC/CSMigrationResult.swift @@ -90,15 +90,15 @@ public final class CSMigrationResult: NSObject, CoreStoreObjectiveCType { - parameter failure: the block to execute on failure. The block passes an `NSError` argument that pertains to the actual error. */ @objc - public func handleSuccess(_ success: @noescape (migrationTypes: [CSMigrationType]) -> Void, failure: @noescape (error: NSError) -> Void) { + public func handleSuccess(_ success: (_ migrationTypes: [CSMigrationType]) -> Void, failure: (_ error: NSError) -> Void) { switch self.bridgeToSwift { case .success(let migrationTypes): - success(migrationTypes: migrationTypes.map { $0.bridgeToObjectiveC }) + success(migrationTypes.map { $0.bridgeToObjectiveC }) case .failure(let error): - failure(error: error.bridgeToObjectiveC) + failure(error.bridgeToObjectiveC) } } @@ -110,13 +110,13 @@ public final class CSMigrationResult: NSObject, CoreStoreObjectiveCType { - parameter success: the block to execute on success. The block passes an array of `CSMigrationType`s that indicates the migration steps completed. */ @objc - public func handleSuccess(_ success: @noescape (migrationTypes: [CSMigrationType]) -> Void) { + public func handleSuccess(_ success: (_ migrationTypes: [CSMigrationType]) -> Void) { guard case .success(let migrationTypes) = self.bridgeToSwift else { return } - success(migrationTypes: migrationTypes.map { $0.bridgeToObjectiveC }) + success(migrationTypes.map { $0.bridgeToObjectiveC }) } /** @@ -127,13 +127,13 @@ public final class CSMigrationResult: NSObject, CoreStoreObjectiveCType { - parameter failure: the block to execute on failure. The block passes an `NSError` argument that pertains to the actual error. */ @objc - public func handleFailure(_ failure: @noescape (error: NSError) -> Void) { + public func handleFailure(_ failure: (_ error: NSError) -> Void) { guard case .failure(let error) = self.bridgeToSwift else { return } - failure(error: error.bridgeToObjectiveC) + failure(error.bridgeToObjectiveC) } @@ -144,7 +144,7 @@ public final class CSMigrationResult: NSObject, CoreStoreObjectiveCType { return self.bridgeToSwift.hashValue } - public override func isEqual(_ object: AnyObject?) -> Bool { + public override func isEqual(_ object: Any?) -> Bool { guard let object = object as? CSMigrationResult else { @@ -155,7 +155,7 @@ public final class CSMigrationResult: NSObject, CoreStoreObjectiveCType { public override var description: String { - return "(\(String(reflecting: self.dynamicType))) \(self.bridgeToSwift.coreStoreDumpString)" + return "(\(String(reflecting: type(of: self)))) \(self.bridgeToSwift.coreStoreDumpString)" } diff --git a/Sources/ObjectiveC/CSMigrationType.swift b/Sources/ObjectiveC/CSMigrationType.swift index 4984c0a..49d9197 100644 --- a/Sources/ObjectiveC/CSMigrationType.swift +++ b/Sources/ObjectiveC/CSMigrationType.swift @@ -90,7 +90,7 @@ public final class CSMigrationType: NSObject, CoreStoreObjectiveCType { return self.bridgeToSwift.hashValue } - public override func isEqual(_ object: AnyObject?) -> Bool { + public override func isEqual(_ object: Any?) -> Bool { guard let object = object as? CSMigrationType else { @@ -101,7 +101,7 @@ public final class CSMigrationType: NSObject, CoreStoreObjectiveCType { public override var description: String { - return "(\(String(reflecting: self.dynamicType))) \(self.bridgeToSwift.coreStoreDumpString)" + return "(\(String(reflecting: type(of: self)))) \(self.bridgeToSwift.coreStoreDumpString)" } diff --git a/Sources/ObjectiveC/CSObjectMonitor.swift b/Sources/ObjectiveC/CSObjectMonitor.swift index f61bf8a..65b4c2a 100644 --- a/Sources/ObjectiveC/CSObjectMonitor.swift +++ b/Sources/ObjectiveC/CSObjectMonitor.swift @@ -107,7 +107,7 @@ public final class CSObjectMonitor: NSObject, CoreStoreObjectiveCType { return self.bridgeToSwift.hashValue } - public override func isEqual(_ object: AnyObject?) -> Bool { + public override func isEqual(_ object: Any?) -> Bool { guard let object = object as? CSObjectMonitor else { @@ -118,7 +118,7 @@ public final class CSObjectMonitor: NSObject, CoreStoreObjectiveCType { public override var description: String { - return "(\(String(reflecting: self.dynamicType))) \(self.bridgeToSwift.coreStoreDumpString)" + return "(\(String(reflecting: type(of: self)))) \(self.bridgeToSwift.coreStoreDumpString)" } diff --git a/Sources/ObjectiveC/CSOrderBy.swift b/Sources/ObjectiveC/CSOrderBy.swift index bf079b3..052e881 100644 --- a/Sources/ObjectiveC/CSOrderBy.swift +++ b/Sources/ObjectiveC/CSOrderBy.swift @@ -84,7 +84,7 @@ public final class CSOrderBy: NSObject, CSFetchClause, CSQueryClause, CSDeleteCl return self.bridgeToSwift.hashValue } - public override func isEqual(_ object: AnyObject?) -> Bool { + public override func isEqual(_ object: Any?) -> Bool { guard let object = object as? CSOrderBy else { @@ -95,7 +95,7 @@ public final class CSOrderBy: NSObject, CSFetchClause, CSQueryClause, CSDeleteCl public override var description: String { - return "(\(String(reflecting: self.dynamicType))) \(self.bridgeToSwift.coreStoreDumpString)" + return "(\(String(reflecting: type(of: self)))) \(self.bridgeToSwift.coreStoreDumpString)" } diff --git a/Sources/ObjectiveC/CSSQliteStore.swift b/Sources/ObjectiveC/CSSQliteStore.swift index 18cc8c3..f11e97c 100644 --- a/Sources/ObjectiveC/CSSQliteStore.swift +++ b/Sources/ObjectiveC/CSSQliteStore.swift @@ -170,7 +170,7 @@ public final class CSSQLiteStore: NSObject, CSLocalStorage, CoreStoreObjectiveCT return ObjectIdentifier(self.bridgeToSwift).hashValue } - public override func isEqual(_ object: AnyObject?) -> Bool { + public override func isEqual(_ object: Any?) -> Bool { guard let object = object as? CSSQLiteStore else { @@ -181,7 +181,7 @@ public final class CSSQLiteStore: NSObject, CSLocalStorage, CoreStoreObjectiveCT public override var description: String { - return "(\(String(reflecting: self.dynamicType))) \(self.bridgeToSwift.coreStoreDumpString)" + return "(\(String(reflecting: type(of: self)))) \(self.bridgeToSwift.coreStoreDumpString)" } diff --git a/Sources/ObjectiveC/CSSaveResult.swift b/Sources/ObjectiveC/CSSaveResult.swift index 49238d0..863e5bd 100644 --- a/Sources/ObjectiveC/CSSaveResult.swift +++ b/Sources/ObjectiveC/CSSaveResult.swift @@ -90,15 +90,15 @@ public final class CSSaveResult: NSObject, CoreStoreObjectiveCType { - parameter failure: the block to execute on failure. The block passes an `NSError` argument that pertains to the actual error. */ @objc - public func handleSuccess(_ success: @noescape (hasChanges: Bool) -> Void, failure: @noescape (error: NSError) -> Void) { + public func handleSuccess(_ success: (_ hasChanges: Bool) -> Void, failure: (_ error: NSError) -> Void) { switch self.bridgeToSwift { case .success(let hasChanges): - success(hasChanges: hasChanges) + success(hasChanges) case .failure(let error): - failure(error: error.bridgeToObjectiveC) + failure(error.bridgeToObjectiveC) } } @@ -110,13 +110,13 @@ public final class CSSaveResult: NSObject, CoreStoreObjectiveCType { - parameter success: the block to execute on success. The block passes a `BOOL` argument that indicates if there were any changes made. */ @objc - public func handleSuccess(_ success: @noescape (hasChanges: Bool) -> Void) { + public func handleSuccess(_ success: (_ hasChanges: Bool) -> Void) { guard case .success(let hasChanges) = self.bridgeToSwift else { return } - success(hasChanges: hasChanges) + success(hasChanges) } /** @@ -127,13 +127,13 @@ public final class CSSaveResult: NSObject, CoreStoreObjectiveCType { - parameter failure: the block to execute on failure. The block passes an `NSError` argument that pertains to the actual error. */ @objc - public func handleFailure(_ failure: @noescape (error: NSError) -> Void) { + public func handleFailure(_ failure: (_ error: NSError) -> Void) { guard case .failure(let error) = self.bridgeToSwift else { return } - failure(error: error.bridgeToObjectiveC) + failure(error.bridgeToObjectiveC) } @@ -144,7 +144,7 @@ public final class CSSaveResult: NSObject, CoreStoreObjectiveCType { return self.bridgeToSwift.hashValue } - public override func isEqual(_ object: AnyObject?) -> Bool { + public override func isEqual(_ object: Any?) -> Bool { guard let object = object as? CSSaveResult else { @@ -155,7 +155,7 @@ public final class CSSaveResult: NSObject, CoreStoreObjectiveCType { public override var description: String { - return "(\(String(reflecting: self.dynamicType))) \(self.bridgeToSwift.coreStoreDumpString)" + return "(\(String(reflecting: type(of: self)))) \(self.bridgeToSwift.coreStoreDumpString)" } diff --git a/Sources/ObjectiveC/CSSectionBy.swift b/Sources/ObjectiveC/CSSectionBy.swift index d4781b8..b08d7c6 100644 --- a/Sources/ObjectiveC/CSSectionBy.swift +++ b/Sources/ObjectiveC/CSSectionBy.swift @@ -59,7 +59,7 @@ public final class CSSectionBy: NSObject, CoreStoreObjectiveCType { - returns: a `CSSectionBy` clause with the key path to use to group `CSListMonitor` objects into sections */ @objc - public static func keyPath(_ sectionKeyPath: KeyPath, sectionIndexTransformer: (sectionName: String?) -> String?) -> CSSectionBy { + public static func keyPath(_ sectionKeyPath: KeyPath, sectionIndexTransformer: (_ sectionName: String?) -> String?) -> CSSectionBy { return self.init(SectionBy(sectionKeyPath, sectionIndexTransformer)) } @@ -69,7 +69,7 @@ public final class CSSectionBy: NSObject, CoreStoreObjectiveCType { public override var description: String { - return "(\(String(reflecting: self.dynamicType))) \(self.bridgeToSwift.coreStoreDumpString)" + return "(\(String(reflecting: type(of: self)))) \(self.bridgeToSwift.coreStoreDumpString)" } diff --git a/Sources/ObjectiveC/CSSelect.swift b/Sources/ObjectiveC/CSSelect.swift index 32416d1..63236d6 100644 --- a/Sources/ObjectiveC/CSSelect.swift +++ b/Sources/ObjectiveC/CSSelect.swift @@ -164,7 +164,7 @@ public final class CSSelectTerm: NSObject, CoreStoreObjectiveCType { return self.bridgeToSwift.hashValue } - public override func isEqual(_ object: AnyObject?) -> Bool { + public override func isEqual(_ object: Any?) -> Bool { guard let object = object as? CSSelectTerm else { @@ -335,10 +335,10 @@ public final class CSSelect: NSObject { public override var hash: Int { return self.attributeType.hashValue - ^ self.selectTerms.map { $0.hashValue }.reduce(0, combine: ^) + ^ self.selectTerms.map { $0.hashValue }.reduce(0, ^) } - public override func isEqual(_ object: AnyObject?) -> Bool { + public override func isEqual(_ object: Any?) -> Bool { guard let object = object as? CSSelect else { @@ -350,7 +350,7 @@ public final class CSSelect: NSObject { public override var description: String { - return "(\(String(reflecting: self.dynamicType))) \(self.bridgeToSwift.coreStoreDumpString)" + return "(\(String(reflecting: type(of: self)))) \(self.bridgeToSwift.coreStoreDumpString)" } diff --git a/Sources/ObjectiveC/CSSetupResult.swift b/Sources/ObjectiveC/CSSetupResult.swift index 6d4034e..fe2d383 100644 --- a/Sources/ObjectiveC/CSSetupResult.swift +++ b/Sources/ObjectiveC/CSSetupResult.swift @@ -76,15 +76,15 @@ public final class CSSetupResult: NSObject { - parameter failure: the block to execute on failure. The block passes an `NSError` argument that pertains to the actual error. */ @objc - public func handleSuccess(_ success: @noescape (storage: CSStorageInterface) -> Void, failure: @noescape (error: NSError) -> Void) { + public func handleSuccess(_ success: (_ storage: CSStorageInterface) -> Void, failure: (_ error: NSError) -> Void) { if let storage = self.storage { - success(storage: storage) + success(storage) } else { - failure(error: self.error!) + failure(self.error!) } } @@ -96,13 +96,13 @@ public final class CSSetupResult: NSObject { - parameter success: the block to execute on success. The block passes a `BOOL` argument that indicates if there were any changes made. */ @objc - public func handleSuccess(_ success: @noescape (storage: CSStorageInterface) -> Void) { + public func handleSuccess(_ success: (_ storage: CSStorageInterface) -> Void) { guard let storage = self.storage else { return } - success(storage: storage) + success(storage) } /** @@ -113,13 +113,13 @@ public final class CSSetupResult: NSObject { - parameter failure: the block to execute on failure. The block passes an `NSError` argument that pertains to the actual error. */ @objc - public func handleFailure(_ failure: @noescape (error: NSError) -> Void) { + public func handleFailure(_ failure: (_ error: NSError) -> Void) { guard let error = self.error else { return } - failure(error: error) + failure(error) } @@ -134,7 +134,7 @@ public final class CSSetupResult: NSObject { return self.isSuccess.hashValue ^ self.error!.hashValue } - public override func isEqual(_ object: AnyObject?) -> Bool { + public override func isEqual(_ object: Any?) -> Bool { guard let object = object as? CSSetupResult else { @@ -146,13 +146,13 @@ public final class CSSetupResult: NSObject { public override var description: String { - return "(\(String(reflecting: self.dynamicType))) \(self.bridgeToSwift.coreStoreDumpString)" + return "(\(String(reflecting: type(of: self)))) \(self.bridgeToSwift.coreStoreDumpString)" } // MARK: CoreStoreObjectiveCType - public required init(_ swiftValue: SetupResult) { + public required init(_ swiftValue: SetupResult) where T: CoreStoreSwiftType, T.ObjectiveCType: CSStorageInterface { switch swiftValue { diff --git a/Sources/ObjectiveC/CSSynchronousDataTransaction.swift b/Sources/ObjectiveC/CSSynchronousDataTransaction.swift index 767b25c..103bb8e 100644 --- a/Sources/ObjectiveC/CSSynchronousDataTransaction.swift +++ b/Sources/ObjectiveC/CSSynchronousDataTransaction.swift @@ -59,7 +59,7 @@ public final class CSSynchronousDataTransaction: CSBaseDataTransaction { */ @objc @discardableResult - public func beginSynchronous(_ closure: (transaction: CSSynchronousDataTransaction) -> Void) -> CSSaveResult? { + public func beginSynchronous(_ closure: @escaping (_ transaction: CSSynchronousDataTransaction) -> Void) -> CSSaveResult? { return bridge { @@ -75,7 +75,7 @@ public final class CSSynchronousDataTransaction: CSBaseDataTransaction { public override var description: String { - return "(\(String(reflecting: self.dynamicType))) \(self.bridgeToSwift.coreStoreDumpString)" + return "(\(String(reflecting: type(of: self)))) \(self.bridgeToSwift.coreStoreDumpString)" } diff --git a/Sources/ObjectiveC/CSTweak.swift b/Sources/ObjectiveC/CSTweak.swift index f8540f3..78981d3 100644 --- a/Sources/ObjectiveC/CSTweak.swift +++ b/Sources/ObjectiveC/CSTweak.swift @@ -41,7 +41,7 @@ public final class CSTweak: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau The block to customize the `NSFetchRequest` */ @objc - public var block: (fetchRequest: NSFetchRequest) -> Void { + public var block: (_ fetchRequest: NSFetchRequest) -> Void { return self.bridgeToSwift.closure } @@ -53,7 +53,7 @@ public final class CSTweak: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau - parameter block: the block to customize the `NSFetchRequest` */ @objc - public convenience init(block: (fetchRequest: NSFetchRequest) -> Void) { + public convenience init(block: (_ fetchRequest: NSFetchRequest) -> Void) { self.init(Tweak(block)) } @@ -63,7 +63,7 @@ public final class CSTweak: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau public override var description: String { - return "(\(String(reflecting: self.dynamicType))) \(self.bridgeToSwift.coreStoreDumpString)" + return "(\(String(reflecting: type(of: self)))) \(self.bridgeToSwift.coreStoreDumpString)" } diff --git a/Sources/ObjectiveC/CSUnsafeDataTransaction.swift b/Sources/ObjectiveC/CSUnsafeDataTransaction.swift index bebf956..83fb5f2 100644 --- a/Sources/ObjectiveC/CSUnsafeDataTransaction.swift +++ b/Sources/ObjectiveC/CSUnsafeDataTransaction.swift @@ -43,11 +43,11 @@ public final class CSUnsafeDataTransaction: CSBaseDataTransaction { - parameter completion: the block executed after the save completes. Success or failure is reported by the `CSSaveResult` argument of the block. */ @objc - public func commit(_ completion: ((result: CSSaveResult) -> Void)?) { + public func commit(_ completion: ((_ result: CSSaveResult) -> Void)?) { self.bridgeToSwift.commit { (result) in - completion?(result: result.bridgeToObjectiveC) + completion?(result.bridgeToObjectiveC) } } @@ -166,7 +166,7 @@ public final class CSUnsafeDataTransaction: CSBaseDataTransaction { public override var description: String { - return "(\(String(reflecting: self.dynamicType))) \(self.bridgeToSwift.coreStoreDumpString)" + return "(\(String(reflecting: type(of: self)))) \(self.bridgeToSwift.coreStoreDumpString)" } diff --git a/Sources/ObjectiveC/CSWhere.swift b/Sources/ObjectiveC/CSWhere.swift index 28e2d7e..61551fb 100644 --- a/Sources/ObjectiveC/CSWhere.swift +++ b/Sources/ObjectiveC/CSWhere.swift @@ -121,7 +121,7 @@ public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau return self.bridgeToSwift.hashValue } - public override func isEqual(_ object: AnyObject?) -> Bool { + public override func isEqual(_ object: Any?) -> Bool { guard let object = object as? CSWhere else { @@ -132,7 +132,7 @@ public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau public override var description: String { - return "(\(String(reflecting: self.dynamicType))) \(self.bridgeToSwift.coreStoreDumpString)" + return "(\(String(reflecting: type(of: self)))) \(self.bridgeToSwift.coreStoreDumpString)" } diff --git a/Sources/ObjectiveC/CoreStoreBridge.swift b/Sources/ObjectiveC/CoreStoreBridge.swift index ab0c832..3d94843 100644 --- a/Sources/ObjectiveC/CoreStoreBridge.swift +++ b/Sources/ObjectiveC/CoreStoreBridge.swift @@ -79,17 +79,17 @@ public extension CoreStoreSwiftType where ObjectiveCType: CoreStoreObjectiveCTyp // MARK: - Internal -internal func bridge(_ closure: @noescape () -> T) -> T.ObjectiveCType { +internal func bridge(_ closure: () -> T) -> T.ObjectiveCType where T.ObjectiveCType: CoreStoreObjectiveCType, T == T.ObjectiveCType.SwiftType { return closure().bridgeToObjectiveC } -internal func bridge(_ closure: @noescape () -> T?) -> T.ObjectiveCType? { +internal func bridge(_ closure: () -> T?) -> T.ObjectiveCType? where T.ObjectiveCType: CoreStoreObjectiveCType, T == T.ObjectiveCType.SwiftType { return closure()?.bridgeToObjectiveC } -internal func bridge(_ closure: @noescape () throws -> T) throws -> T.ObjectiveCType { +internal func bridge(_ closure: () throws -> T) throws -> T.ObjectiveCType where T.ObjectiveCType: CoreStoreObjectiveCType, T == T.ObjectiveCType.SwiftType { do { @@ -101,7 +101,7 @@ internal func bridge Void) throws { +internal func bridge(_ closure: () throws -> Void) throws { do { @@ -113,7 +113,7 @@ internal func bridge(_ closure: @noescape () throws -> Void) throws { } } -internal func bridge(_ error: NSErrorPointer, _ closure: @noescape () throws -> T) -> T.ObjectiveCType? { +internal func bridge(_ error: NSErrorPointer, _ closure: () throws -> T) -> T.ObjectiveCType? { do { @@ -128,7 +128,7 @@ internal func bridge(_ error: NSErrorPointer, _ closure: } } -internal func bridge(_ error: NSErrorPointer, _ closure: @noescape () throws -> Void) -> Bool { +internal func bridge(_ error: NSErrorPointer, _ closure: () throws -> Void) -> Bool { do { @@ -143,7 +143,7 @@ internal func bridge(_ error: NSErrorPointer, _ closure: @noescape () throws -> } } -internal func bridge(_ error: NSErrorPointer, _ closure: @noescape () throws -> T?) -> T? { +internal func bridge(_ error: NSErrorPointer, _ closure: () throws -> T?) -> T? { do { @@ -158,7 +158,7 @@ internal func bridge(_ error: NSErrorPointer, _ closure: @noescape () throws } } -internal func bridge(_ error: NSErrorPointer, _ closure: @noescape () throws -> [T]) -> [T.ObjectiveCType]? { +internal func bridge(_ error: NSErrorPointer, _ closure: () throws -> [T]) -> [T.ObjectiveCType]? { do { diff --git a/Sources/ObjectiveC/NSProgress+ObjectiveC.swift b/Sources/ObjectiveC/NSProgress+ObjectiveC.swift index 1ce6365..9416b81 100644 --- a/Sources/ObjectiveC/NSProgress+ObjectiveC.swift +++ b/Sources/ObjectiveC/NSProgress+ObjectiveC.swift @@ -36,7 +36,7 @@ public extension Progress { - parameter closure: the closure to execute on progress change */ @objc - public func cs_setProgressHandler(_ closure: ((progress: Progress) -> Void)?) { + public func cs_setProgressHandler(_ closure: ((_ progress: Progress) -> Void)?) { self.setProgressHandler(closure) } diff --git a/Sources/Observing/DataStack+Observing.swift b/Sources/Observing/DataStack+Observing.swift index dcb2d95..16b9116 100644 --- a/Sources/Observing/DataStack+Observing.swift +++ b/Sources/Observing/DataStack+Observing.swift @@ -25,9 +25,6 @@ import Foundation import CoreData -#if USE_FRAMEWORKS - import GCDKit -#endif #if os(iOS) || os(watchOS) || os(tvOS) diff --git a/Sources/Observing/ListMonitor.swift b/Sources/Observing/ListMonitor.swift index ed3b365..340c670 100644 --- a/Sources/Observing/ListMonitor.swift +++ b/Sources/Observing/ListMonitor.swift @@ -25,9 +25,6 @@ import Foundation import CoreData -#if USE_FRAMEWORKS - import GCDKit -#endif #if os(iOS) || os(watchOS) || os(tvOS) @@ -191,7 +188,7 @@ public final class ListMonitor: Hashable { */ public func hasObjectsInSection(_ section: Int) -> Bool { - return self.numberOfObjectsInSection(safeSectionIndex: section) > 0 + return self.numberOfObjectsInSection(safeSectionIndex: section)! > 0 } /** @@ -406,7 +403,7 @@ public final class ListMonitor: Hashable { - parameter observer: a `ListObserver` to send change notifications to */ - public func addObserver(_ observer: U) { + public func addObserver(_ observer: U) where U.ListEntityType == T { self.unregisterObserver(observer) self.registerObserver( @@ -441,7 +438,7 @@ public final class ListMonitor: Hashable { - parameter observer: a `ListObjectObserver` to send change notifications to */ - public func addObserver(_ observer: U) { + public func addObserver(_ observer: U) where U.ListEntityType == T { self.unregisterObserver(observer) self.registerObserver( @@ -495,7 +492,7 @@ public final class ListMonitor: Hashable { - parameter observer: a `ListSectionObserver` to send change notifications to */ - public func addObserver(_ observer: U) { + public func addObserver(_ observer: U) where U.ListEntityType == T { self.unregisterObserver(observer) self.registerObserver( @@ -556,7 +553,7 @@ public final class ListMonitor: Hashable { - parameter observer: a `ListObserver` to unregister notifications to */ - public func removeObserver(_ observer: U) { + public func removeObserver(_ observer: U) where U.ListEntityType == T { self.unregisterObserver(observer) } @@ -607,7 +604,7 @@ public final class ListMonitor: Hashable { // MARK: Internal - internal convenience init(dataStack: DataStack, from: From, sectionBy: SectionBy?, applyFetchClauses: (fetchRequest: NSFetchRequest) -> Void) { + internal convenience init(dataStack: DataStack, from: From, sectionBy: SectionBy?, applyFetchClauses: (_ fetchRequest: NSFetchRequest) -> Void) { self.init( context: dataStack.mainContext, @@ -619,7 +616,7 @@ public final class ListMonitor: Hashable { ) } - internal convenience init(dataStack: DataStack, from: From, sectionBy: SectionBy?, applyFetchClauses: (fetchRequest: NSFetchRequest) -> Void, createAsynchronously: (ListMonitor) -> Void) { + internal convenience init(dataStack: DataStack, from: From, sectionBy: SectionBy?, applyFetchClauses: (_ fetchRequest: NSFetchRequest) -> Void, createAsynchronously: (ListMonitor) -> Void) { self.init( context: dataStack.mainContext, @@ -631,7 +628,7 @@ public final class ListMonitor: Hashable { ) } - internal convenience init(unsafeTransaction: UnsafeDataTransaction, from: From, sectionBy: SectionBy?, applyFetchClauses: (fetchRequest: NSFetchRequest) -> Void) { + internal convenience init(unsafeTransaction: UnsafeDataTransaction, from: From, sectionBy: SectionBy?, applyFetchClauses: (_ fetchRequest: NSFetchRequest) -> Void) { self.init( context: unsafeTransaction.context, @@ -643,7 +640,7 @@ public final class ListMonitor: Hashable { ) } - internal convenience init(unsafeTransaction: UnsafeDataTransaction, from: From, sectionBy: SectionBy?, applyFetchClauses: (fetchRequest: NSFetchRequest) -> Void, createAsynchronously: (ListMonitor) -> Void) { + internal convenience init(unsafeTransaction: UnsafeDataTransaction, from: From, sectionBy: SectionBy?, applyFetchClauses: (_ fetchRequest: NSFetchRequest) -> Void, createAsynchronously: (ListMonitor) -> Void) { self.init( context: unsafeTransaction.context, @@ -660,7 +657,7 @@ public final class ListMonitor: Hashable { return unsafeBitCast(self, to: ListMonitor.self) } - internal func registerChangeNotification(_ notificationKey: UnsafePointer, name: Notification.Name, toObserver observer: AnyObject, callback: (monitor: ListMonitor) -> Void) { + internal func registerChangeNotification(_ notificationKey: UnsafeRawPointer, name: Notification.Name, toObserver observer: AnyObject, callback: @escaping (_ monitor: ListMonitor) -> Void) { cs_setAssociatedRetainedObject( NotificationObserver( @@ -672,7 +669,7 @@ public final class ListMonitor: Hashable { return } - callback(monitor: self) + callback(self) } ), forKey: notificationKey, @@ -680,7 +677,7 @@ public final class ListMonitor: Hashable { ) } - internal func registerObjectNotification(_ notificationKey: UnsafePointer, name: Notification.Name, toObserver observer: AnyObject, callback: (monitor: ListMonitor, object: T, indexPath: IndexPath?, newIndexPath: IndexPath?) -> Void) { + internal func registerObjectNotification(_ notificationKey: UnsafeRawPointer, name: Notification.Name, toObserver observer: AnyObject, callback: @escaping (_ monitor: ListMonitor, _ object: T, _ indexPath: IndexPath?, _ newIndexPath: IndexPath?) -> Void) { cs_setAssociatedRetainedObject( NotificationObserver( @@ -695,10 +692,10 @@ public final class ListMonitor: Hashable { return } callback( - monitor: self, - object: object, - indexPath: userInfo[String(IndexPath.self)] as? IndexPath, - newIndexPath: userInfo["\(String(IndexPath.self)).New"] as? IndexPath + self, + object, + userInfo[String(IndexPath.self)] as? IndexPath, + userInfo["\(String(IndexPath.self)).New"] as? IndexPath ) } ), @@ -707,7 +704,7 @@ public final class ListMonitor: Hashable { ) } - internal func registerSectionNotification(_ notificationKey: UnsafePointer, name: Notification.Name, toObserver observer: AnyObject, callback: (monitor: ListMonitor, sectionInfo: NSFetchedResultsSectionInfo, sectionIndex: Int) -> Void) { + internal func registerSectionNotification(_ notificationKey: UnsafeRawPointer, name: Notification.Name, toObserver observer: AnyObject, callback: @escaping (_ monitor: ListMonitor, _ sectionInfo: NSFetchedResultsSectionInfo, _ sectionIndex: Int) -> Void) { cs_setAssociatedRetainedObject( NotificationObserver( @@ -722,11 +719,7 @@ public final class ListMonitor: Hashable { return } - callback( - monitor: self, - sectionInfo: sectionInfo, - sectionIndex: sectionIndex - ) + callback(self, sectionInfo, sectionIndex) } ), forKey: notificationKey, @@ -734,7 +727,7 @@ public final class ListMonitor: Hashable { ) } - internal func registerObserver(_ observer: U, willChange: (observer: U, monitor: ListMonitor) -> Void, didChange: (observer: U, monitor: ListMonitor) -> Void, willRefetch: (observer: U, monitor: ListMonitor) -> Void, didRefetch: (observer: U, monitor: ListMonitor) -> Void) { + internal func registerObserver(_ observer: U, willChange: @escaping (_ observer: U, _ monitor: ListMonitor) -> Void, didChange: @escaping (_ observer: U, _ monitor: ListMonitor) -> Void, willRefetch: @escaping (_ observer: U, _ monitor: ListMonitor) -> Void, didRefetch: @escaping (_ observer: U, _ monitor: ListMonitor) -> Void) { CoreStore.assert( Thread.isMainThread, @@ -794,7 +787,7 @@ public final class ListMonitor: Hashable { ) } - internal func registerObserver(_ observer: U, didInsertObject: (observer: U, monitor: ListMonitor, object: T, toIndexPath: IndexPath) -> Void, didDeleteObject: (observer: U, monitor: ListMonitor, object: T, fromIndexPath: IndexPath) -> Void, didUpdateObject: (observer: U, monitor: ListMonitor, object: T, atIndexPath: IndexPath) -> Void, didMoveObject: (observer: U, monitor: ListMonitor, object: T, fromIndexPath: IndexPath, toIndexPath: IndexPath) -> Void) { + internal func registerObserver(_ observer: U, didInsertObject: @escaping (_ observer: U, _ monitor: ListMonitor, _ object: T, _ toIndexPath: IndexPath) -> Void, didDeleteObject: @escaping (_ observer: U, _ monitor: ListMonitor, _ object: T, _ fromIndexPath: IndexPath) -> Void, didUpdateObject: @escaping (_ observer: U, _ monitor: ListMonitor, _ object: T, _ atIndexPath: IndexPath) -> Void, didMoveObject: @escaping (_ observer: U, _ monitor: ListMonitor, _ object: T, _ fromIndexPath: IndexPath, _ toIndexPath: IndexPath) -> Void) { CoreStore.assert( Thread.isMainThread, @@ -876,7 +869,7 @@ public final class ListMonitor: Hashable { ) } - internal func registerObserver(_ observer: U, didInsertSection: (observer: U, monitor: ListMonitor, sectionInfo: NSFetchedResultsSectionInfo, toIndex: Int) -> Void, didDeleteSection: (observer: U, monitor: ListMonitor, sectionInfo: NSFetchedResultsSectionInfo, fromIndex: Int) -> Void) { + internal func registerObserver(_ observer: U, didInsertSection: @escaping (_ observer: U, _ monitor: ListMonitor, _ sectionInfo: NSFetchedResultsSectionInfo, _ toIndex: Int) -> Void, didDeleteSection: @escaping (_ observer: U, _ monitor: ListMonitor, _ sectionInfo: NSFetchedResultsSectionInfo, _ fromIndex: Int) -> Void) { CoreStore.assert( Thread.isMainThread, @@ -942,7 +935,7 @@ public final class ListMonitor: Hashable { cs_setAssociatedRetainedObject(nilValue, forKey: &self.didDeleteSectionKey, inObject: observer) } - internal func refetch(_ applyFetchClauses: (fetchRequest: NSFetchRequest) -> Void) { + internal func refetch(_ applyFetchClauses: @escaping (_ fetchRequest: NSFetchRequest) -> Void) { CoreStore.assert( Thread.isMainThread, @@ -979,7 +972,7 @@ public final class ListMonitor: Hashable { try! self.fetchedResultsController.performFetchFromSpecifiedStores() - GCDQueue.main.async { [weak self] () -> Void in + DispatchQueue.main.async { [weak self] () -> Void in guard let `self` = self else { @@ -1022,12 +1015,12 @@ public final class ListMonitor: Hashable { private let fetchedResultsController: CoreStoreFetchedResultsController private let fetchedResultsControllerDelegate: FetchedResultsControllerDelegate - private let sectionIndexTransformer: (sectionName: KeyPath?) -> String? + private let sectionIndexTransformer: (_ sectionName: KeyPath?) -> String? private var observerForWillChangePersistentStore: NotificationObserver! private var observerForDidChangePersistentStore: NotificationObserver! - private let taskGroup = GCDGroup() - private let transactionQueue: GCDQueue - private var applyFetchClauses: (fetchRequest: NSFetchRequest) -> Void + private let taskGroup = DispatchGroup() + private let transactionQueue: DispatchQueue + private var applyFetchClauses: (_ fetchRequest: NSFetchRequest) -> Void private var isPersistentStoreChanging: Bool = false { @@ -1050,7 +1043,7 @@ public final class ListMonitor: Hashable { } } - private init(context: NSManagedObjectContext, transactionQueue: GCDQueue, from: From, sectionBy: SectionBy?, applyFetchClauses: (fetchRequest: NSFetchRequest) -> Void, createAsynchronously: ((ListMonitor) -> Void)?) { + private init(context: NSManagedObjectContext, transactionQueue: DispatchQueue, from: From, sectionBy: SectionBy?, applyFetchClauses: (_ fetchRequest: NSFetchRequest) -> Void, createAsynchronously: ((ListMonitor) -> Void)?) { let fetchRequest = CoreStoreFetchRequest() fetchRequest.fetchLimit = 0 diff --git a/Sources/Observing/ObjectMonitor.swift b/Sources/Observing/ObjectMonitor.swift index 489eb76..60afb41 100644 --- a/Sources/Observing/ObjectMonitor.swift +++ b/Sources/Observing/ObjectMonitor.swift @@ -25,9 +25,6 @@ import Foundation import CoreData -#if USE_FRAMEWORKS - import GCDKit -#endif #if os(iOS) || os(watchOS) || os(tvOS) @@ -73,7 +70,7 @@ public final class ObjectMonitor { - parameter observer: an `ObjectObserver` to send change notifications to */ - public func addObserver(_ observer: U) { + public func addObserver(_ observer: U) where U.ObjectEntityType == EntityType { self.unregisterObserver(observer) self.registerObserver( @@ -100,7 +97,7 @@ public final class ObjectMonitor { - parameter observer: an `ObjectObserver` to unregister notifications to */ - public func removeObserver(_ observer: U) { + public func removeObserver(_ observer: U) where U.ObjectEntityType == EntityType { self.unregisterObserver(observer) } @@ -126,7 +123,7 @@ public final class ObjectMonitor { self.init(context: unsafeTransaction.context, object: object) } - internal func registerObserver(_ observer: U, willChangeObject: (observer: U, monitor: ObjectMonitor, object: EntityType) -> Void, didDeleteObject: (observer: U, monitor: ObjectMonitor, object: EntityType) -> Void, didUpdateObject: (observer: U, monitor: ObjectMonitor, object: EntityType, changedPersistentKeys: Set) -> Void) { + internal func registerObserver(_ observer: U, willChangeObject: @escaping (_ observer: U, _ monitor: ObjectMonitor, _ object: EntityType) -> Void, didDeleteObject: @escaping (_ observer: U, _ monitor: ObjectMonitor, _ object: EntityType) -> Void, didUpdateObject: @escaping (_ observer: U, _ monitor: ObjectMonitor, _ object: EntityType, _ changedPersistentKeys: Set) -> Void) { CoreStore.assert( Thread.isMainThread, @@ -142,7 +139,7 @@ public final class ObjectMonitor { return } - willChangeObject(observer: observer, monitor: monitor, object: object) + willChangeObject(observer, monitor, object) } ) self.registerObjectNotification( @@ -155,7 +152,7 @@ public final class ObjectMonitor { return } - didDeleteObject(observer: observer, monitor: monitor, object: object) + didDeleteObject(observer, monitor, object) } ) self.registerObjectNotification( @@ -182,12 +179,7 @@ public final class ObjectMonitor { } self.lastCommittedAttributes = currentCommitedAttributes - didUpdateObject( - observer: observer, - monitor: monitor, - object: object, - changedPersistentKeys: changedKeys - ) + didUpdateObject(observer, monitor, object, changedKeys) } ) } @@ -255,7 +247,7 @@ public final class ObjectMonitor { self.lastCommittedAttributes = (self.object?.committedValues(forKeys: nil) as? [String: NSObject]) ?? [:] } - private func registerChangeNotification(_ notificationKey: UnsafePointer, name: Notification.Name, toObserver observer: AnyObject, callback: (monitor: ObjectMonitor) -> Void) { + private func registerChangeNotification(_ notificationKey: UnsafeRawPointer, name: Notification.Name, toObserver observer: AnyObject, callback: @escaping (_ monitor: ObjectMonitor) -> Void) { cs_setAssociatedRetainedObject( NotificationObserver( @@ -267,7 +259,7 @@ public final class ObjectMonitor { return } - callback(monitor: self) + callback(self) } ), forKey: notificationKey, @@ -275,7 +267,7 @@ public final class ObjectMonitor { ) } - private func registerObjectNotification(_ notificationKey: UnsafePointer, name: Notification.Name, toObserver observer: AnyObject, callback: (monitor: ObjectMonitor, object: EntityType) -> Void) { + private func registerObjectNotification(_ notificationKey: UnsafeRawPointer, name: Notification.Name, toObserver observer: AnyObject, callback: @escaping (_ monitor: ObjectMonitor, _ object: EntityType) -> Void) { cs_setAssociatedRetainedObject( NotificationObserver( @@ -285,11 +277,11 @@ public final class ObjectMonitor { guard let `self` = self, let userInfo = note.userInfo, - let object = userInfo[String(NSManagedObject.self)] as? EntityType else { + let object = userInfo[String(describing: NSManagedObject.self)] as? EntityType else { return } - callback(monitor: self, object: object) + callback(self, object) } ), forKey: notificationKey, @@ -338,7 +330,7 @@ extension ObjectMonitor: FetchedResultsControllerHandler { NotificationCenter.default.post( name: Notification.Name.objectMonitorDidDeleteObject, object: self, - userInfo: [String(NSManagedObject.self): anObject] + userInfo: [String(describing: NSManagedObject.self): anObject] ) case .update, @@ -346,7 +338,7 @@ extension ObjectMonitor: FetchedResultsControllerHandler { NotificationCenter.default.post( name: Notification.Name.objectMonitorDidUpdateObject, object: self, - userInfo: [String(NSManagedObject.self): anObject] + userInfo: [String(describing: NSManagedObject.self): anObject] ) default: @@ -365,11 +357,11 @@ extension ObjectMonitor: FetchedResultsControllerHandler { // MARK: - Notification.Name -private extension Notification.Name { +fileprivate extension Notification.Name { - private static let objectMonitorWillChangeObject = Notification.Name(rawValue: "objectMonitorWillChangeObject") - private static let objectMonitorDidDeleteObject = Notification.Name(rawValue: "objectMonitorDidDeleteObject") - private static let objectMonitorDidUpdateObject = Notification.Name(rawValue: "objectMonitorDidUpdateObject") + fileprivate static let objectMonitorWillChangeObject = Notification.Name(rawValue: "objectMonitorWillChangeObject") + fileprivate static let objectMonitorDidDeleteObject = Notification.Name(rawValue: "objectMonitorDidDeleteObject") + fileprivate static let objectMonitorDidUpdateObject = Notification.Name(rawValue: "objectMonitorDidUpdateObject") } #endif diff --git a/Sources/Observing/SectionBy.swift b/Sources/Observing/SectionBy.swift index ebc5385..abc4c8b 100644 --- a/Sources/Observing/SectionBy.swift +++ b/Sources/Observing/SectionBy.swift @@ -60,7 +60,7 @@ public struct SectionBy { - parameter sectionKeyPath: the key path to use to group the objects into sections - parameter sectionIndexTransformer: a closure to transform the value for the key path to an appropriate section name */ - public init(_ sectionKeyPath: KeyPath, _ sectionIndexTransformer: (sectionName: String?) -> String?) { + public init(_ sectionKeyPath: KeyPath, _ sectionIndexTransformer: @escaping (_ sectionName: String?) -> String?) { self.sectionKeyPath = sectionKeyPath self.sectionIndexTransformer = sectionIndexTransformer @@ -70,7 +70,7 @@ public struct SectionBy { // MARK: Internal internal let sectionKeyPath: KeyPath - internal let sectionIndexTransformer: (sectionName: KeyPath?) -> String? + internal let sectionIndexTransformer: (_ sectionName: KeyPath?) -> String? } #endif diff --git a/Sources/Observing/UnsafeDataTransaction+Observing.swift b/Sources/Observing/UnsafeDataTransaction+Observing.swift index d279a94..8b043f5 100644 --- a/Sources/Observing/UnsafeDataTransaction+Observing.swift +++ b/Sources/Observing/UnsafeDataTransaction+Observing.swift @@ -25,9 +25,6 @@ import Foundation import CoreData -#if USE_FRAMEWORKS - import GCDKit -#endif #if os(iOS) || os(watchOS) || os(tvOS) diff --git a/Sources/Setup/CoreStore+Setup.swift b/Sources/Setup/CoreStore+Setup.swift index d2f9362..211caa2 100644 --- a/Sources/Setup/CoreStore+Setup.swift +++ b/Sources/Setup/CoreStore+Setup.swift @@ -25,9 +25,6 @@ import Foundation import CoreData -#if USE_FRAMEWORKS - import GCDKit -#endif // MARK: - CoreStore @@ -81,7 +78,7 @@ public extension CoreStore { - returns: the `StorageInterface` added to the `defaultStack` */ @discardableResult - public static func addStorageAndWait(_ storeType: T.Type) throws -> T { + public static func addStorageAndWait(_ storeType: T.Type) throws -> T where T: DefaultInitializableStore { return try self.defaultStack.addStorageAndWait(storeType.init()) } @@ -111,7 +108,7 @@ public extension CoreStore { - returns: the local storage added to the `defaultStack` */ @discardableResult - public static func addStorageAndWait(_ storageType: T.Type) throws -> T { + public static func addStorageAndWait(_ storageType: T.Type) throws -> T where T: DefaultInitializableStore { return try self.defaultStack.addStorageAndWait(storageType.init()) } diff --git a/Sources/Setup/DataStack.swift b/Sources/Setup/DataStack.swift index 9fae2c9..ef9389b 100644 --- a/Sources/Setup/DataStack.swift +++ b/Sources/Setup/DataStack.swift @@ -25,9 +25,6 @@ import Foundation import CoreData -#if USE_FRAMEWORKS - import GCDKit -#endif // MARK: - DataStack @@ -135,7 +132,7 @@ public final class DataStack { - returns: the `StorageInterface` added to the stack */ @discardableResult - public func addStorageAndWait(_ storeType: T.Type) throws -> T { + public func addStorageAndWait(_ storeType: T.Type) throws -> T where T: DefaultInitializableStore { return try self.addStorageAndWait(storeType.init()) } @@ -189,7 +186,7 @@ public final class DataStack { - returns: the local storage added to the stack */ @discardableResult - public func addStorageAndWait(_ storageType: T.Type) throws -> T { + public func addStorageAndWait(_ storageType: T.Type) throws -> T where T: DefaultInitializableStore { return try self.addStorageAndWait(storageType.init()) } @@ -258,7 +255,7 @@ public final class DataStack { catch let error as NSError where storage.localStorageOptions.contains(.recreateStoreOnModelMismatch) && error.isCoreDataMigrationError { let metadata = try NSPersistentStoreCoordinator.metadataForPersistentStore( - ofType: storage.dynamicType.storeType, + ofType: type(of: storage).storeType, at: fileURL, options: storeOptions ) @@ -353,7 +350,7 @@ public final class DataStack { catch let error as NSError where storage.cloudStorageOptions.contains(.recreateLocalStoreOnModelMismatch) && error.isCoreDataMigrationError { let metadata = try NSPersistentStoreCoordinator.metadataForPersistentStore( - ofType: storage.dynamicType.storeType, + ofType: type(of: storage).storeType, at: cacheFileURL, options: storeOptions ) @@ -381,22 +378,28 @@ public final class DataStack { // MARK: Internal - internal static let applicationName = (Bundle.main.objectForInfoDictionaryKey("CFBundleName") as? String) ?? "CoreData" + internal static let applicationName = (Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String) ?? "CoreData" internal let coordinator: NSPersistentStoreCoordinator internal let rootSavingContext: NSManagedObjectContext internal let mainContext: NSManagedObjectContext internal let model: NSManagedObjectModel internal let migrationChain: MigrationChain - internal let childTransactionQueue = GCDQueue.createSerial("com.coreStore.dataStack.childTransactionQueue") - internal let storeMetadataUpdateQueue = GCDQueue.createConcurrent("com.coreStore.persistentStoreBarrierQueue") + internal let childTransactionQueue = DispatchQueue(serialWith: "com.coreStore.dataStack.childTransactionQueue") + internal let storeMetadataUpdateQueue = DispatchQueue(concurrentWith: "com.coreStore.persistentStoreBarrierQueue") internal let migrationQueue: OperationQueue = { let migrationQueue = OperationQueue() migrationQueue.maxConcurrentOperationCount = 1 migrationQueue.name = "com.coreStore.migrationOperationQueue" migrationQueue.qualityOfService = .utility - migrationQueue.underlyingQueue = GCDQueue.createSerial("com.coreStore.migrationQueue").dispatchQueue() + migrationQueue.underlyingQueue = DispatchQueue( + label: "com.coreStore.migrationQueue", + qos: .userInitiated, + attributes: .allZeros, + autoreleaseFrequency: .workItem, + target: nil + ) return migrationQueue }() @@ -415,7 +418,7 @@ public final class DataStack { internal func persistentStoresForEntityClass(_ entityClass: AnyClass) -> [NSPersistentStore]? { var returnValue: [NSPersistentStore]? = nil - self.storeMetadataUpdateQueue.barrierSync { + self.storeMetadataUpdateQueue.sync(flags: .barrier) { returnValue = self.entityConfigurationsMapping[NSStringFromClass(entityClass)]?.map { @@ -428,7 +431,7 @@ public final class DataStack { internal func persistentStoreForEntityClass(_ entityClass: AnyClass, configuration: String?, inferStoreIfPossible: Bool) -> (store: NSPersistentStore?, isAmbiguous: Bool) { var returnValue: (store: NSPersistentStore?, isAmbiguous: Bool) = (store: nil, isAmbiguous: false) - self.storeMetadataUpdateQueue.barrierSync { + self.storeMetadataUpdateQueue.sync(flags: .barrier) { let configurationsForEntity = self.entityConfigurationsMapping[NSStringFromClass(entityClass)] ?? [] if let configuration = configuration { @@ -462,14 +465,14 @@ public final class DataStack { internal func createPersistentStoreFromStorage(_ storage: StorageInterface, finalURL: URL?, finalStoreOptions: [String: AnyObject]?) throws -> NSPersistentStore { let persistentStore = try self.coordinator.addPersistentStore( - ofType: storage.dynamicType.storeType, + ofType: type(of: storage).storeType, configurationName: storage.configuration, at: finalURL, options: finalStoreOptions ) persistentStore.storageInterface = storage - self.storeMetadataUpdateQueue.barrierAsync { + self.storeMetadataUpdateQueue.async(flags: .barrier) { let configurationName = persistentStore.configurationName self.configurationStoreMapping[configurationName] = persistentStore diff --git a/Sources/Setup/StorageInterfaces/ICloudStore.swift b/Sources/Setup/StorageInterfaces/ICloudStore.swift index 116e9ee..3de49f8 100644 --- a/Sources/Setup/StorageInterfaces/ICloudStore.swift +++ b/Sources/Setup/StorageInterfaces/ICloudStore.swift @@ -434,9 +434,9 @@ public class ICloudStore: CloudStorage { let options = [ NSSQLitePragmasOption: ["journal_mode": "DELETE"], NSPersistentStoreRemoveUbiquitousMetadataOption: true - ] + ] as [String : Any] let store = try journalUpdatingCoordinator.addPersistentStore( - ofType: self.dynamicType.storeType, + ofType: type(of: self).storeType, configurationName: self.configuration, at: cacheFileURL, options: options @@ -470,7 +470,7 @@ public class ICloudStore: CloudStorage { private weak var dataStack: DataStack? - private func registerNotification(_ notificationKey: UnsafePointer, name: Notification.Name, toObserver observer: T, callback: (observer: T, storage: ICloudStore, dataStack: DataStack) -> Void) { + private func registerNotification(_ notificationKey: UnsafeRawPointer, name: Notification.Name, toObserver observer: T, callback: @escaping (_ observer: T, _ storage: ICloudStore, _ dataStack: DataStack) -> Void) { cs_setAssociatedRetainedObject( NotificationObserver( @@ -485,7 +485,7 @@ public class ICloudStore: CloudStorage { return } - callback(observer: observer, storage: self, dataStack: dataStack) + callback(observer, self, dataStack) } ), forKey: notificationKey, diff --git a/Sources/Setup/StorageInterfaces/LegacySQLiteStore.swift b/Sources/Setup/StorageInterfaces/LegacySQLiteStore.swift index d5f5420..b16e141 100644 --- a/Sources/Setup/StorageInterfaces/LegacySQLiteStore.swift +++ b/Sources/Setup/StorageInterfaces/LegacySQLiteStore.swift @@ -25,9 +25,6 @@ import Foundation import CoreData -#if USE_FRAMEWORKS - import GCDKit -#endif // MARK: - LegacySQLiteStore @@ -177,7 +174,7 @@ public final class LegacySQLiteStore: LocalStorage, DefaultInitializableStore { let journalUpdatingCoordinator = NSPersistentStoreCoordinator(managedObjectModel: soureModel) let store = try journalUpdatingCoordinator.addPersistentStore( - ofType: self.dynamicType.storeType, + ofType: type(of: self).storeType, configurationName: self.configuration, at: fileURL, options: [NSSQLitePragmasOption: ["journal_mode": "DELETE"]] @@ -197,7 +194,7 @@ public final class LegacySQLiteStore: LocalStorage, DefaultInitializableStore { attributes: nil ) try fileManager.moveItem(at: fileURL, to: temporaryFile) - GCDQueue.background.async { + DispatchQueue.global(qos: .background).async { _ = try? fileManager.removeItem(at: temporaryFile) } diff --git a/Sources/Setup/StorageInterfaces/SQLiteStore.swift b/Sources/Setup/StorageInterfaces/SQLiteStore.swift index 10e7a3c..d481372 100644 --- a/Sources/Setup/StorageInterfaces/SQLiteStore.swift +++ b/Sources/Setup/StorageInterfaces/SQLiteStore.swift @@ -24,9 +24,6 @@ // import CoreData -#if USE_FRAMEWORKS - import GCDKit -#endif // MARK: - SQLiteStore @@ -174,7 +171,7 @@ public final class SQLiteStore: LocalStorage, DefaultInitializableStore { let journalUpdatingCoordinator = NSPersistentStoreCoordinator(managedObjectModel: soureModel) let store = try journalUpdatingCoordinator.addPersistentStore( - ofType: self.dynamicType.storeType, + ofType: type(of: self).storeType, configurationName: self.configuration, at: fileURL, options: [NSSQLitePragmasOption: ["journal_mode": "DELETE"]] @@ -194,7 +191,7 @@ public final class SQLiteStore: LocalStorage, DefaultInitializableStore { attributes: nil ) try fileManager.moveItem(at: fileURL, to: temporaryFile) - GCDQueue.background.async { + DispatchQueue.global(qos: .background).async { _ = try? fileManager.removeItem(at: temporaryFile) } @@ -226,9 +223,9 @@ public final class SQLiteStore: LocalStorage, DefaultInitializableStore { ) }() - internal static let defaultFileURL = try! SQLiteStore.defaultRootDirectory + internal static let defaultFileURL = SQLiteStore.defaultRootDirectory .appendingPathComponent( - (Bundle.main.objectForInfoDictionaryKey("CFBundleName") as? String) ?? "CoreData", + (Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String) ?? "CoreData", isDirectory: false ) .appendingPathExtension("sqlite") diff --git a/Sources/Setup/StorageInterfaces/StorageInterface.swift b/Sources/Setup/StorageInterfaces/StorageInterface.swift index 425500b..662b980 100644 --- a/Sources/Setup/StorageInterfaces/StorageInterface.swift +++ b/Sources/Setup/StorageInterfaces/StorageInterface.swift @@ -82,7 +82,7 @@ public protocol DefaultInitializableStore: StorageInterface { /** The `LocalStorageOptions` provides settings that tells the `DataStack` how to setup the persistent store for `LocalStorage` implementers. */ -public struct LocalStorageOptions: OptionSet, NilLiteralConvertible { +public struct LocalStorageOptions: OptionSet, ExpressibleByNilLiteral { /** Tells the `DataStack` that the store should not be migrated or recreated, and should simply fail on model mismatch @@ -119,7 +119,7 @@ public struct LocalStorageOptions: OptionSet, NilLiteralConvertible { public let rawValue: Int - // MARK: NilLiteralConvertible + // MARK: ExpressibleByNilLiteral public init(nilLiteral: ()) { @@ -165,7 +165,7 @@ internal extension LocalStorage { internal func matchesPersistentStore(_ persistentStore: NSPersistentStore) -> Bool { - return persistentStore.type == self.dynamicType.storeType + return persistentStore.type == type(of: self).storeType && persistentStore.configurationName == (self.configuration ?? Into.defaultConfigurationName) && persistentStore.url == self.fileURL } @@ -177,7 +177,7 @@ internal extension LocalStorage { /** The `CloudStorageOptions` provides settings that tells the `DataStack` how to setup the persistent store for `LocalStorage` implementers. */ -public struct CloudStorageOptions: OptionSet, NilLiteralConvertible { +public struct CloudStorageOptions: OptionSet, ExpressibleByNilLiteral { /** Tells the `DataStack` that the store should not be migrated or recreated, and should simply fail on model mismatch @@ -208,7 +208,7 @@ public struct CloudStorageOptions: OptionSet, NilLiteralConvertible { public let rawValue: Int - // MARK: NilLiteralConvertible + // MARK: ExpressibleByNilLiteral public init(nilLiteral: ()) { @@ -249,7 +249,7 @@ internal extension CloudStorage { internal func matchesPersistentStore(_ persistentStore: NSPersistentStore) -> Bool { - guard persistentStore.type == self.dynamicType.storeType + guard persistentStore.type == type(of: self).storeType && persistentStore.configurationName == (self.configuration ?? Into.defaultConfigurationName) else { return false diff --git a/Sources/Transactions/AsynchronousDataTransaction.swift b/Sources/Transactions/AsynchronousDataTransaction.swift index 5d8040b..3be1509 100644 --- a/Sources/Transactions/AsynchronousDataTransaction.swift +++ b/Sources/Transactions/AsynchronousDataTransaction.swift @@ -25,9 +25,6 @@ import Foundation import CoreData -#if USE_FRAMEWORKS - import GCDKit -#endif // MARK: - AsynchronousDataTransaction @@ -42,7 +39,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { - parameter completion: the block executed after the save completes. Success or failure is reported by the `SaveResult` argument of the block. */ - public func commit(_ completion: (result: SaveResult) -> Void = { _ in }) { + public func commit(_ completion: @escaping (_ result: SaveResult) -> Void = { _ in }) { CoreStore.assert( self.transactionQueue.isCurrentExecutionContext(), @@ -54,12 +51,12 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { ) self.isCommitted = true - let group = GCDGroup() + let group = DispatchGroup() group.enter() self.context.saveAsynchronouslyWithCompletion { (result) -> Void in self.result = result - completion(result: result) + completion(result) group.leave() } group.wait() @@ -72,7 +69,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { - returns: a `SaveResult` value indicating success or failure, or `nil` if the transaction was not comitted synchronously */ @discardableResult - public func beginSynchronous(_ closure: (transaction: SynchronousDataTransaction) -> Void) -> SaveResult? { + public func beginSynchronous(_ closure: (_ transaction: SynchronousDataTransaction) -> Void) -> SaveResult? { CoreStore.assert( self.transactionQueue.isCurrentExecutionContext(), @@ -178,7 +175,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { - parameter objects: the `NSManagedObject`s type to be deleted */ - public override func delete(_ objects: S) { + public override func delete(_ objects: S) where S.Iterator.Element: NSManagedObject { CoreStore.assert( !self.isCommitted, @@ -191,7 +188,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { // MARK: Internal - internal init(mainContext: NSManagedObjectContext, queue: GCDQueue, closure: (transaction: AsynchronousDataTransaction) -> Void) { + internal init(mainContext: NSManagedObjectContext, queue: DispatchQueue, closure: (_ transaction: AsynchronousDataTransaction) -> Void) { self.closure = closure @@ -233,5 +230,5 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { // MARK: Private - private let closure: (transaction: AsynchronousDataTransaction) -> Void + private let closure: (_ transaction: AsynchronousDataTransaction) -> Void } diff --git a/Sources/Transactions/BaseDataTransaction.swift b/Sources/Transactions/BaseDataTransaction.swift index 651f58d..f7c0cdd 100644 --- a/Sources/Transactions/BaseDataTransaction.swift +++ b/Sources/Transactions/BaseDataTransaction.swift @@ -25,9 +25,6 @@ import Foundation import CoreData -#if USE_FRAMEWORKS - import GCDKit -#endif // MARK: - BaseDataTransaction @@ -87,7 +84,7 @@ public /*abstract*/ class BaseDataTransaction { switch context.parentStack!.persistentStoreForEntityClass( entityClass, configuration: into.configuration - ?? into.dynamicType.defaultConfigurationName, + ?? type(of: into).defaultConfigurationName, inferStoreIfPossible: false ) { @@ -187,7 +184,7 @@ public /*abstract*/ class BaseDataTransaction { - parameter objects: the `NSManagedObject`s to be deleted */ - public func delete(_ objects: S) { + public func delete(_ objects: S) where S.Iterator.Element: NSManagedObject { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -453,8 +450,8 @@ public /*abstract*/ class BaseDataTransaction { // MARK: Internal internal let context: NSManagedObjectContext - internal let transactionQueue: GCDQueue - internal let childTransactionQueue = GCDQueue.createSerial("com.corestore.datastack.childtransactionqueue") + internal let transactionQueue: DispatchQueue + internal let childTransactionQueue = DispatchQueue(serialWith: "com.corestore.datastack.childtransactionqueue") internal let supportsUndo: Bool internal let bypassesQueueing: Bool @@ -462,7 +459,7 @@ public /*abstract*/ class BaseDataTransaction { internal var isCommitted = false internal var result: SaveResult? - internal init(mainContext: NSManagedObjectContext, queue: GCDQueue, supportsUndo: Bool, bypassesQueueing: Bool) { + internal init(mainContext: NSManagedObjectContext, queue: DispatchQueue, supportsUndo: Bool, bypassesQueueing: Bool) { let context = mainContext.temporaryContextInTransactionWithConcurrencyType( queue == .main diff --git a/Sources/Transactions/CoreStore+Transaction.swift b/Sources/Transactions/CoreStore+Transaction.swift index aaa1277..7176b8c 100644 --- a/Sources/Transactions/CoreStore+Transaction.swift +++ b/Sources/Transactions/CoreStore+Transaction.swift @@ -35,7 +35,7 @@ public extension CoreStore { - parameter closure: the block where creates, updates, and deletes can be made to the transaction. Transaction blocks are executed serially in a background queue, and all changes are made from a concurrent `NSManagedObjectContext`. */ - public static func beginAsynchronous(_ closure: (transaction: AsynchronousDataTransaction) -> Void) { + public static func beginAsynchronous(_ closure: (_ transaction: AsynchronousDataTransaction) -> Void) { self.defaultStack.beginAsynchronous(closure) } @@ -47,7 +47,7 @@ public extension CoreStore { - returns: a `SaveResult` value indicating success or failure, or `nil` if the transaction was not comitted synchronously */ @discardableResult - public static func beginSynchronous(_ closure: (transaction: SynchronousDataTransaction) -> Void) -> SaveResult? { + public static func beginSynchronous(_ closure: (_ transaction: SynchronousDataTransaction) -> Void) -> SaveResult? { return self.defaultStack.beginSynchronous(closure) } diff --git a/Sources/Transactions/DataStack+Transaction.swift b/Sources/Transactions/DataStack+Transaction.swift index db91ecc..b0fc270 100644 --- a/Sources/Transactions/DataStack+Transaction.swift +++ b/Sources/Transactions/DataStack+Transaction.swift @@ -25,9 +25,6 @@ import Foundation import CoreData -#if USE_FRAMEWORKS - import GCDKit -#endif // MARK: - DataStack @@ -39,7 +36,7 @@ public extension DataStack { - parameter closure: the block where creates, updates, and deletes can be made to the transaction. Transaction blocks are executed serially in a background queue, and all changes are made from a concurrent `NSManagedObjectContext`. */ - public func beginAsynchronous(_ closure: (transaction: AsynchronousDataTransaction) -> Void) { + public func beginAsynchronous(_ closure: (_ transaction: AsynchronousDataTransaction) -> Void) { AsynchronousDataTransaction( mainContext: self.rootSavingContext, @@ -54,7 +51,7 @@ public extension DataStack { - returns: a `SaveResult` value indicating success or failure, or `nil` if the transaction was not comitted synchronously */ @discardableResult - public func beginSynchronous(_ closure: (transaction: SynchronousDataTransaction) -> Void) -> SaveResult? { + public func beginSynchronous(_ closure: (_ transaction: SynchronousDataTransaction) -> Void) -> SaveResult? { return SynchronousDataTransaction( mainContext: self.rootSavingContext, diff --git a/Sources/Transactions/SaveResult.swift b/Sources/Transactions/SaveResult.swift index 338593c..c0a9856 100644 --- a/Sources/Transactions/SaveResult.swift +++ b/Sources/Transactions/SaveResult.swift @@ -70,6 +70,19 @@ public enum SaveResult: Hashable { case failure(CoreStoreError) + /** + Returns `true` if the result indicates `.success`, `false` if the result is `.failure`. + */ + public var boolValue: Bool { + + switch self { + + case .success: return true + case .failure: return false + } + } + + // MARK: Hashable public var hashValue: Int { @@ -99,21 +112,6 @@ public enum SaveResult: Hashable { } -// MARK: - SaveResult: BooleanType - -extension SaveResult: Boolean { - - public var boolValue: Bool { - - switch self { - - case .success: return true - case .failure: return false - } - } -} - - // MARK: - SaveResult: Equatable public func == (lhs: SaveResult, rhs: SaveResult) -> Bool { diff --git a/Sources/Transactions/SynchronousDataTransaction.swift b/Sources/Transactions/SynchronousDataTransaction.swift index 6d6a272..947a9dc 100644 --- a/Sources/Transactions/SynchronousDataTransaction.swift +++ b/Sources/Transactions/SynchronousDataTransaction.swift @@ -25,9 +25,6 @@ import Foundation import CoreData -#if USE_FRAMEWORKS - import GCDKit -#endif // MARK: - SynchronousDataTransaction @@ -67,7 +64,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction { - returns: a `SaveResult` value indicating success or failure, or `nil` if the transaction was not comitted synchronously */ @discardableResult - public func beginSynchronous(_ closure: (transaction: SynchronousDataTransaction) -> Void) -> SaveResult? { + public func beginSynchronous(_ closure: (_ transaction: SynchronousDataTransaction) -> Void) -> SaveResult? { CoreStore.assert( self.transactionQueue.isCurrentExecutionContext(), @@ -173,7 +170,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction { - parameter objects: the `NSManagedObject`s to be deleted */ - public override func delete(_ objects: S) { + public override func delete(_ objects: S) where S.Iterator.Element: NSManagedObject { CoreStore.assert( !self.isCommitted, @@ -186,7 +183,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction { // MARK: Internal - internal init(mainContext: NSManagedObjectContext, queue: GCDQueue, closure: (transaction: SynchronousDataTransaction) -> Void) { + internal init(mainContext: NSManagedObjectContext, queue: DispatchQueue, closure: (_ transaction: SynchronousDataTransaction) -> Void) { self.closure = closure @@ -213,5 +210,5 @@ public final class SynchronousDataTransaction: BaseDataTransaction { // MARK: Private - private let closure: (transaction: SynchronousDataTransaction) -> Void + private let closure: (_ transaction: SynchronousDataTransaction) -> Void } diff --git a/Sources/Transactions/UnsafeDataTransaction.swift b/Sources/Transactions/UnsafeDataTransaction.swift index 56256f9..e36ee70 100644 --- a/Sources/Transactions/UnsafeDataTransaction.swift +++ b/Sources/Transactions/UnsafeDataTransaction.swift @@ -25,9 +25,6 @@ import Foundation import CoreData -#if USE_FRAMEWORKS - import GCDKit -#endif // MARK: - UnsafeDataTransaction @@ -42,12 +39,12 @@ public final class UnsafeDataTransaction: BaseDataTransaction { - parameter completion: the block executed after the save completes. Success or failure is reported by the `SaveResult` argument of the block. */ - public func commit(_ completion: (result: SaveResult) -> Void) { + public func commit(_ completion: @escaping (_ result: SaveResult) -> Void) { self.context.saveAsynchronouslyWithCompletion { (result) -> Void in self.result = result - completion(result: result) + completion(result) } } @@ -105,7 +102,7 @@ public final class UnsafeDataTransaction: BaseDataTransaction { - parameter closure: the closure where changes can be made prior to the flush - throws: an error thrown from `closure`, or an error thrown by Core Data (usually validation errors or conflict errors) */ - public func flush(closure: @noescape () throws -> Void) rethrows { + public func flush(closure: () throws -> Void) rethrows { try closure() self.context.processPendingChanges() @@ -153,7 +150,7 @@ public final class UnsafeDataTransaction: BaseDataTransaction { // MARK: Internal - internal init(mainContext: NSManagedObjectContext, queue: GCDQueue, supportsUndo: Bool) { + internal init(mainContext: NSManagedObjectContext, queue: DispatchQueue, supportsUndo: Bool) { super.init(mainContext: mainContext, queue: queue, supportsUndo: supportsUndo, bypassesQueueing: true) }