From 7f9a915d7178b96731ecb829e8f678a787e68f80 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Wed, 7 Jun 2017 20:07:43 +0900 Subject: [PATCH] WIP: Swift 3.2 --- Sources/AsynchronousDataTransaction.swift | 10 ++-- Sources/BaseDataTransaction+Querying.swift | 32 ++++++------ Sources/BaseDataTransaction.swift | 4 +- Sources/CSSelect.swift | 2 +- Sources/CSSetupResult.swift | 2 +- Sources/ClauseTypes.swift | 6 +-- ...reStore+CustomDebugStringConvertible.swift | 2 + Sources/CoreStore+Migration.swift | 2 +- Sources/CoreStore+Observing.swift | 18 +++---- Sources/CoreStore+Querying.swift | 28 +++++----- Sources/CoreStoreFetchRequest+CoreStore.swift | 2 +- .../CoreStoreFetchedResultsController.swift | 6 +-- Sources/CoreStoreObject+Querying.swift | 22 ++++---- Sources/DataStack+Migration.swift | 2 +- Sources/DataStack+Observing.swift | 18 +++---- Sources/DataStack+Querying.swift | 28 +++++----- Sources/DataStack+Transaction.swift | 6 +-- Sources/FetchableSource.swift | 20 ++++---- Sources/From.swift | 4 +- Sources/GroupBy.swift | 2 +- Sources/ImportableUniqueObject.swift | 51 ++++++++----------- Sources/Into.swift | 2 +- Sources/ListMonitor.swift | 4 +- Sources/MigrationChain.swift | 2 +- Sources/NSManagedObjectContext+Querying.swift | 32 ++++++------ Sources/ObjectMonitor.swift | 4 +- Sources/OrderBy.swift | 2 +- Sources/QueryableAttributeType.swift | 12 ++++- Sources/QueryableSource.swift | 8 +-- Sources/Relationship.swift | 18 +++---- Sources/Select.swift | 2 +- Sources/SetupResult.swift | 2 +- Sources/SynchronousDataTransaction.swift | 10 ++-- Sources/Tweak.swift | 2 +- Sources/UnsafeDataTransaction+Observing.swift | 18 +++---- Sources/Value.swift | 12 ++--- Sources/Where.swift | 2 +- 37 files changed, 199 insertions(+), 200 deletions(-) diff --git a/Sources/AsynchronousDataTransaction.swift b/Sources/AsynchronousDataTransaction.swift index 08caeab..d31380b 100644 --- a/Sources/AsynchronousDataTransaction.swift +++ b/Sources/AsynchronousDataTransaction.swift @@ -100,7 +100,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { - parameter into: the `Into` clause indicating the destination `NSManagedObject` or `CoreStoreObject` entity type and the destination configuration - returns: a new `NSManagedObject` or `CoreStoreObject` instance of the specified entity type. */ - public override func create(_ into: Into) -> T { + public override func create(_ into: Into) -> T { CoreStore.assert( !self.isCommitted, @@ -133,7 +133,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { - parameter objectID: the `NSManagedObjectID` for the object to be edited - returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`. */ - public override func edit(_ into: Into, _ objectID: NSManagedObjectID) -> T? { + public override func edit(_ into: Into, _ objectID: NSManagedObjectID) -> T? { CoreStore.assert( !self.isCommitted, @@ -266,9 +266,9 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { } switch childTransaction.result { - case nil: return nil - case (let hasChanges, nil)?: return SaveResult(hasChanges: hasChanges) - case (_, let error?)?: return SaveResult(error) + case .none: return nil + case .some(let hasChanges, nil): return SaveResult(hasChanges: hasChanges) + case .some(_, let error?): return SaveResult(error) } } } diff --git a/Sources/BaseDataTransaction+Querying.swift b/Sources/BaseDataTransaction+Querying.swift index 4fa9893..776507f 100644 --- a/Sources/BaseDataTransaction+Querying.swift +++ b/Sources/BaseDataTransaction+Querying.swift @@ -39,7 +39,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - returns: the number of `DynamicObject`s deleted */ @discardableResult - public func deleteAll(_ from: From, _ deleteClauses: DeleteClause...) -> Int? { + public func deleteAll(_ from: From, _ deleteClauses: DeleteClause...) -> Int? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -57,7 +57,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - returns: the number of `DynamicObject`s deleted */ @discardableResult - public func deleteAll(_ from: From, _ deleteClauses: [DeleteClause]) -> Int? { + public func deleteAll(_ from: From, _ deleteClauses: [DeleteClause]) -> Int? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -121,7 +121,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s */ - public func fetchOne(_ from: From, _ fetchClauses: FetchClause...) -> T? { + public func fetchOne(_ from: From, _ fetchClauses: FetchClause...) -> T? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -137,7 +137,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s */ - public func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) -> T? { + public func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) -> T? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -153,7 +153,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s */ - public func fetchAll(_ from: From, _ fetchClauses: FetchClause...) -> [T]? { + public func fetchAll(_ from: From, _ fetchClauses: FetchClause...) -> [T]? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -169,7 +169,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s */ - public func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) -> [T]? { + public func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) -> [T]? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -185,7 +185,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s */ - public func fetchCount(_ from: From, _ fetchClauses: FetchClause...) -> Int? { + public func fetchCount(_ from: From, _ fetchClauses: FetchClause...) -> Int? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -201,7 +201,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s */ - public func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) -> Int? { + public func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) -> Int? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -217,7 +217,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s */ - public func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) -> NSManagedObjectID? { + public func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) -> NSManagedObjectID? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -233,7 +233,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s */ - public func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? { + public func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -249,7 +249,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s */ - public func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? { + public func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -265,7 +265,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s */ - public func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? { + public func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -287,7 +287,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> U? { + public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> U? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -306,7 +306,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> U? { + public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> U? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -325,7 +325,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> [[String: Any]]? { + public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> [[String: Any]]? { CoreStore.assert( self.isRunningInAllowedQueue(), @@ -344,7 +344,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> [[String: Any]]? { + public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> [[String: Any]]? { CoreStore.assert( self.isRunningInAllowedQueue(), diff --git a/Sources/BaseDataTransaction.swift b/Sources/BaseDataTransaction.swift index dd04b78..3a657f7 100644 --- a/Sources/BaseDataTransaction.swift +++ b/Sources/BaseDataTransaction.swift @@ -50,7 +50,7 @@ public /*abstract*/ class BaseDataTransaction { - parameter into: the `Into` clause indicating the destination `NSManagedObject` or `CoreStoreObject` entity type and the destination configuration - returns: a new `NSManagedObject` or `CoreStoreObject` instance of the specified entity type. */ - public func create(_ into: Into) -> T { + public func create(_ into: Into) -> T { let entityClass = into.entityClass CoreStore.assert( @@ -141,7 +141,7 @@ public /*abstract*/ class BaseDataTransaction { - parameter objectID: the `NSManagedObjectID` for the object to be edited - returns: an editable proxy for the specified `NSManagedObject`. */ - public func edit(_ into: Into, _ objectID: NSManagedObjectID) -> T? { + public func edit(_ into: Into, _ objectID: NSManagedObjectID) -> T? { CoreStore.assert( self.isRunningInAllowedQueue(), diff --git a/Sources/CSSelect.swift b/Sources/CSSelect.swift index 74fa947..09f1799 100644 --- a/Sources/CSSelect.swift +++ b/Sources/CSSelect.swift @@ -365,7 +365,7 @@ public final class CSSelect: NSObject { super.init() } - public init(_ swiftValue: Select) { + public init(_ swiftValue: Select) { self.attributeType = .undefinedAttributeType self.selectTerms = swiftValue.selectTerms diff --git a/Sources/CSSetupResult.swift b/Sources/CSSetupResult.swift index 124b255..2171945 100644 --- a/Sources/CSSetupResult.swift +++ b/Sources/CSSetupResult.swift @@ -152,7 +152,7 @@ public final class CSSetupResult: NSObject { // MARK: CoreStoreObjectiveCType - public required init(_ swiftValue: SetupResult) where T: CoreStoreSwiftType, T.ObjectiveCType: CSStorageInterface { + public required init(_ swiftValue: SetupResult) where T: CoreStoreSwiftType, T.ObjectiveCType: CSStorageInterface { switch swiftValue { diff --git a/Sources/ClauseTypes.swift b/Sources/ClauseTypes.swift index df207bb..b03f3e2 100644 --- a/Sources/ClauseTypes.swift +++ b/Sources/ClauseTypes.swift @@ -34,7 +34,7 @@ import CoreData */ public protocol FetchClause { - func applyToFetchRequest(_ fetchRequest: NSFetchRequest) + func applyToFetchRequest(_ fetchRequest: NSFetchRequest) } @@ -45,7 +45,7 @@ public protocol FetchClause { */ public protocol QueryClause { - func applyToFetchRequest(_ fetchRequest: NSFetchRequest) + func applyToFetchRequest(_ fetchRequest: NSFetchRequest) } @@ -56,5 +56,5 @@ public protocol QueryClause { */ public protocol DeleteClause { - func applyToFetchRequest(_ fetchRequest: NSFetchRequest) + func applyToFetchRequest(_ fetchRequest: NSFetchRequest) } diff --git a/Sources/CoreStore+CustomDebugStringConvertible.swift b/Sources/CoreStore+CustomDebugStringConvertible.swift index dc197e3..51038aa 100644 --- a/Sources/CoreStore+CustomDebugStringConvertible.swift +++ b/Sources/CoreStore+CustomDebugStringConvertible.swift @@ -1214,6 +1214,8 @@ extension NSAttributeType: CoreStoreDebugStringConvertible { case .binaryDataAttributeType: return ".binaryDataAttributeType" case .transformableAttributeType: return ".transformableAttributeType" case .objectIDAttributeType: return ".objectIDAttributeType" + case .UUIDAttributeType: return ".UUIDAttributeType" + case .URIAttributeType: return ".URIAttributeType" } } } diff --git a/Sources/CoreStore+Migration.swift b/Sources/CoreStore+Migration.swift index 8f16239..f93d6c9 100644 --- a/Sources/CoreStore+Migration.swift +++ b/Sources/CoreStore+Migration.swift @@ -47,7 +47,7 @@ public extension CoreStore { - 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 static func addStorage(_ storage: T, completion: @escaping (SetupResult) -> Void) { + public static func addStorage(_ storage: T, completion: @escaping (SetupResult) -> Void) { self.defaultStack.addStorage(storage, completion: completion) } diff --git a/Sources/CoreStore+Observing.swift b/Sources/CoreStore+Observing.swift index 53828fd..d5e543b 100644 --- a/Sources/CoreStore+Observing.swift +++ b/Sources/CoreStore+Observing.swift @@ -38,7 +38,7 @@ public extension CoreStore { - parameter object: the `DynamicObject` to observe changes from - returns: a `ObjectMonitor` that monitors changes to `object` */ - public static func monitorObject(_ object: T) -> ObjectMonitor { + public static func monitorObject(_ object: T) -> ObjectMonitor { return self.defaultStack.monitorObject(object) } @@ -50,7 +50,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: a `ListMonitor` instance that monitors changes to the list */ - public static func monitorList(_ from: From, _ fetchClauses: FetchClause...) -> ListMonitor { + public static func monitorList(_ from: From, _ fetchClauses: FetchClause...) -> ListMonitor { return self.defaultStack.monitorList(from, fetchClauses) } @@ -62,7 +62,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: a `ListMonitor` instance that monitors changes to the list */ - public static func monitorList(_ from: From, _ fetchClauses: [FetchClause]) -> ListMonitor { + public static func monitorList(_ from: From, _ fetchClauses: [FetchClause]) -> ListMonitor { return self.defaultStack.monitorList(from, fetchClauses) } @@ -74,7 +74,7 @@ public extension CoreStore { - parameter from: a `From` clause indicating the entity type - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. */ - public static func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: FetchClause...) { + public static func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: FetchClause...) { self.defaultStack.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses) } @@ -86,7 +86,7 @@ public extension CoreStore { - parameter from: a `From` clause indicating the entity type - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. */ - public static func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: [FetchClause]) { + public static func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: [FetchClause]) { self.defaultStack.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses) } @@ -99,7 +99,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: a `ListMonitor` instance that monitors changes to the list */ - public static func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor { + public static func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor { return self.defaultStack.monitorSectionedList(from, sectionBy, fetchClauses) } @@ -112,7 +112,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: a `ListMonitor` instance that monitors changes to the list */ - public static func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor { + public static func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor { return self.defaultStack.monitorSectionedList(from, sectionBy, fetchClauses) } @@ -125,7 +125,7 @@ public extension CoreStore { - parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections. - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. */ - public static func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) { + public static func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) { self.defaultStack.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses) } @@ -138,7 +138,7 @@ public extension CoreStore { - parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections. - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. */ - public static func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) { + public static func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) { self.defaultStack.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses) } diff --git a/Sources/CoreStore+Querying.swift b/Sources/CoreStore+Querying.swift index 67e7812..48cf117 100644 --- a/Sources/CoreStore+Querying.swift +++ b/Sources/CoreStore+Querying.swift @@ -82,7 +82,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s */ - public static func fetchOne(_ from: From, _ fetchClauses: FetchClause...) -> T? { + public static func fetchOne(_ from: From, _ fetchClauses: FetchClause...) -> T? { return self.defaultStack.fetchOne(from, fetchClauses) } @@ -94,7 +94,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s */ - public static func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) -> T? { + public static func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) -> T? { return self.defaultStack.fetchOne(from, fetchClauses) } @@ -106,7 +106,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s */ - public static func fetchAll(_ from: From, _ fetchClauses: FetchClause...) -> [T]? { + public static func fetchAll(_ from: From, _ fetchClauses: FetchClause...) -> [T]? { return self.defaultStack.fetchAll(from, fetchClauses) } @@ -118,7 +118,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s */ - public static func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) -> [T]? { + public static func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) -> [T]? { return self.defaultStack.fetchAll(from, fetchClauses) } @@ -130,7 +130,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s */ - public static func fetchCount(_ from: From, _ fetchClauses: FetchClause...) -> Int? { + public static func fetchCount(_ from: From, _ fetchClauses: FetchClause...) -> Int? { return self.defaultStack.fetchCount(from, fetchClauses) } @@ -142,7 +142,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s */ - public static func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) -> Int? { + public static func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) -> Int? { return self.defaultStack.fetchCount(from, fetchClauses) } @@ -154,7 +154,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s */ - public static func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) -> NSManagedObjectID? { + public static func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) -> NSManagedObjectID? { return self.defaultStack.fetchObjectID(from, fetchClauses) } @@ -166,7 +166,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s */ - public static func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? { + public static func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? { return self.defaultStack.fetchObjectID(from, fetchClauses) } @@ -178,7 +178,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s */ - public static func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? { + public static func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? { return self.defaultStack.fetchObjectIDs(from, fetchClauses) } @@ -190,7 +190,7 @@ public extension CoreStore { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s */ - public static func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? { + public static func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? { return self.defaultStack.fetchObjectIDs(from, fetchClauses) } @@ -205,7 +205,7 @@ public extension CoreStore { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - public static func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> U? { + public static func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> U? { return self.defaultStack.queryValue(from, selectClause, queryClauses) } @@ -220,7 +220,7 @@ public extension CoreStore { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - public static func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> U? { + public static func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> U? { return self.defaultStack.queryValue(from, selectClause, queryClauses) } @@ -235,7 +235,7 @@ public extension CoreStore { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - public static func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> [[String: Any]]? { + public static func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> [[String: Any]]? { return self.defaultStack.queryAttributes(from, selectClause, queryClauses) } @@ -250,7 +250,7 @@ public extension CoreStore { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - public static func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> [[String: Any]]? { + public static func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> [[String: Any]]? { return self.defaultStack.queryAttributes(from, selectClause, queryClauses) } diff --git a/Sources/CoreStoreFetchRequest+CoreStore.swift b/Sources/CoreStoreFetchRequest+CoreStore.swift index cd2c3fb..735b6c6 100644 --- a/Sources/CoreStoreFetchRequest+CoreStore.swift +++ b/Sources/CoreStoreFetchRequest+CoreStore.swift @@ -34,7 +34,7 @@ internal extension CoreStoreFetchRequest { // MARK: Internal @nonobjc @inline(__always) - internal func dynamicCast() -> NSFetchRequest { + internal func dynamicCast() -> NSFetchRequest { return unsafeBitCast(self, to: NSFetchRequest.self) } diff --git a/Sources/CoreStoreFetchedResultsController.swift b/Sources/CoreStoreFetchedResultsController.swift index a5802d3..6fe2cf3 100644 --- a/Sources/CoreStoreFetchedResultsController.swift +++ b/Sources/CoreStoreFetchedResultsController.swift @@ -35,7 +35,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll // MARK: Internal @nonobjc - internal convenience init(dataStack: DataStack, fetchRequest: NSFetchRequest, from: From, sectionBy: SectionBy? = nil, applyFetchClauses: @escaping (_ fetchRequest: NSFetchRequest) -> Void) { + internal convenience init(dataStack: DataStack, fetchRequest: NSFetchRequest, from: From, sectionBy: SectionBy? = nil, applyFetchClauses: @escaping (_ fetchRequest: NSFetchRequest) -> Void) { self.init( context: dataStack.mainContext, @@ -47,7 +47,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll } @nonobjc - internal init(context: NSManagedObjectContext, fetchRequest: NSFetchRequest, from: From, sectionBy: SectionBy? = nil, applyFetchClauses: @escaping (_ fetchRequest: NSFetchRequest) -> Void) { + internal init(context: NSManagedObjectContext, fetchRequest: NSFetchRequest, from: From, sectionBy: SectionBy? = nil, applyFetchClauses: @escaping (_ fetchRequest: NSFetchRequest) -> Void) { _ = from.applyToFetchRequest( fetchRequest, @@ -83,7 +83,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll } @nonobjc - internal func dynamicCast() -> NSFetchedResultsController { + internal func dynamicCast() -> NSFetchedResultsController { return unsafeBitCast(self, to: NSFetchedResultsController.self) } diff --git a/Sources/CoreStoreObject+Querying.swift b/Sources/CoreStoreObject+Querying.swift index 7896b9a..0a87043 100644 --- a/Sources/CoreStoreObject+Querying.swift +++ b/Sources/CoreStoreObject+Querying.swift @@ -37,7 +37,7 @@ public extension DynamicObject where Self: CoreStoreObject { let keyPath: String = Person.keyPath { $0.nickname } ``` */ - public static func keyPath(_ attribute: (Self) -> ValueContainer.Required) -> String { + public static func keyPath(_ attribute: (Self) -> ValueContainer.Required) -> String { return attribute(self.meta).keyPath } @@ -48,7 +48,7 @@ public extension DynamicObject where Self: CoreStoreObject { let keyPath: String = Person.keyPath { $0.nickname } ``` */ - public static func keyPath(_ attribute: (Self) -> ValueContainer.Optional) -> String { + public static func keyPath(_ attribute: (Self) -> ValueContainer.Optional) -> String { return attribute(self.meta).keyPath } @@ -59,7 +59,7 @@ public extension DynamicObject where Self: CoreStoreObject { let keyPath: String = Person.keyPath { $0.pets } ``` */ - public static func keyPath(_ relationship: (Self) -> RelationshipContainer.ToOne) -> String { + public static func keyPath(_ relationship: (Self) -> RelationshipContainer.ToOne) -> String { return relationship(self.meta).keyPath } @@ -70,7 +70,7 @@ public extension DynamicObject where Self: CoreStoreObject { let keyPath: String = Person.keyPath { $0.pets } ``` */ - public static func keyPath(_ relationship: (Self) -> RelationshipContainer.ToManyOrdered) -> String { + public static func keyPath(_ relationship: (Self) -> RelationshipContainer.ToManyOrdered) -> String { return relationship(self.meta).keyPath } @@ -81,7 +81,7 @@ public extension DynamicObject where Self: CoreStoreObject { let keyPath: String = Person.keyPath { $0.pets } ``` */ - public static func keyPath(_ relationship: (Self) -> RelationshipContainer.ToManyUnordered) -> String { + public static func keyPath(_ relationship: (Self) -> RelationshipContainer.ToManyUnordered) -> String { return relationship(self.meta).keyPath } @@ -103,7 +103,7 @@ public extension DynamicObject where Self: CoreStoreObject { let person = CoreStore.fetchAll(From(), Person.orderBy(ascending: { $0.age })) ``` */ - public static func orderBy(ascending attribute: (Self) -> ValueContainer.Required) -> OrderBy { + public static func orderBy(ascending attribute: (Self) -> ValueContainer.Required) -> OrderBy { return OrderBy(.ascending(attribute(self.meta).keyPath)) } @@ -114,7 +114,7 @@ public extension DynamicObject where Self: CoreStoreObject { let person = CoreStore.fetchAll(From(), Person.orderBy(ascending: { $0.age })) ``` */ - public static func orderBy(ascending attribute: (Self) -> ValueContainer.Optional) -> OrderBy { + public static func orderBy(ascending attribute: (Self) -> ValueContainer.Optional) -> OrderBy { return OrderBy(.ascending(attribute(self.meta).keyPath)) } @@ -125,7 +125,7 @@ public extension DynamicObject where Self: CoreStoreObject { let person = CoreStore.fetchAll(From(), Person.orderBy(descending: { $0.age })) ``` */ - public static func orderBy(descending attribute: (Self) -> ValueContainer.Required) -> OrderBy { + public static func orderBy(descending attribute: (Self) -> ValueContainer.Required) -> OrderBy { return OrderBy(.descending(attribute(self.meta).keyPath)) } @@ -136,7 +136,7 @@ public extension DynamicObject where Self: CoreStoreObject { let person = CoreStore.fetchAll(From(), Person.orderBy(descending: { $0.age })) ``` */ - public static func orderBy(descending attribute: (Self) -> ValueContainer.Optional) -> OrderBy { + public static func orderBy(descending attribute: (Self) -> ValueContainer.Optional) -> OrderBy { return OrderBy(.descending(attribute(self.meta).keyPath)) } @@ -145,13 +145,13 @@ public extension DynamicObject where Self: CoreStoreObject { // MARK: Deprecated @available(*, deprecated, renamed: "orderBy(ascending:)") - public static func ascending(_ attribute: (Self) -> ValueContainer.Optional) -> OrderBy { + public static func ascending(_ attribute: (Self) -> ValueContainer.Optional) -> OrderBy { return OrderBy(.ascending(attribute(self.meta).keyPath)) } @available(*, deprecated, renamed: "orderBy(descending:)") - public static func descending(_ attribute: (Self) -> ValueContainer.Optional) -> OrderBy { + public static func descending(_ attribute: (Self) -> ValueContainer.Optional) -> OrderBy { return OrderBy(.descending(attribute(self.meta).keyPath)) } diff --git a/Sources/DataStack+Migration.swift b/Sources/DataStack+Migration.swift index 8d22919..d129ed0 100644 --- a/Sources/DataStack+Migration.swift +++ b/Sources/DataStack+Migration.swift @@ -47,7 +47,7 @@ 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: @escaping (SetupResult) -> Void) { + public func addStorage(_ storage: T, completion: @escaping (SetupResult) -> Void) { self.coordinator.performAsynchronously { diff --git a/Sources/DataStack+Observing.swift b/Sources/DataStack+Observing.swift index 2c5c2ee..e4dea00 100644 --- a/Sources/DataStack+Observing.swift +++ b/Sources/DataStack+Observing.swift @@ -38,7 +38,7 @@ public extension DataStack { - parameter object: the `DynamicObject` to observe changes from - returns: a `ObjectMonitor` that monitors changes to `object` */ - public func monitorObject(_ object: T) -> ObjectMonitor { + public func monitorObject(_ object: T) -> ObjectMonitor { CoreStore.assert( Thread.isMainThread, @@ -54,7 +54,7 @@ public extension DataStack { - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: a `ListMonitor` instance that monitors changes to the list */ - public func monitorList(_ from: From, _ fetchClauses: FetchClause...) -> ListMonitor { + public func monitorList(_ from: From, _ fetchClauses: FetchClause...) -> ListMonitor { return self.monitorList(from, fetchClauses) } @@ -66,7 +66,7 @@ public extension DataStack { - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: a `ListMonitor` instance that monitors changes to the list */ - public func monitorList(_ from: From, _ fetchClauses: [FetchClause]) -> ListMonitor { + public func monitorList(_ from: From, _ fetchClauses: [FetchClause]) -> ListMonitor { CoreStore.assert( Thread.isMainThread, @@ -95,7 +95,7 @@ public extension DataStack { - parameter from: a `From` clause indicating the entity type - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. */ - public func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: FetchClause...) { + public func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: FetchClause...) { self.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses) } @@ -107,7 +107,7 @@ public extension DataStack { - parameter from: a `From` clause indicating the entity type - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. */ - public func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: [FetchClause]) { + public func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: [FetchClause]) { CoreStore.assert( Thread.isMainThread, @@ -138,7 +138,7 @@ public extension DataStack { - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: a `ListMonitor` instance that monitors changes to the list */ - public func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor { + public func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor { return self.monitorSectionedList(from, sectionBy, fetchClauses) } @@ -151,7 +151,7 @@ public extension DataStack { - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: a `ListMonitor` instance that monitors changes to the list */ - public func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor { + public func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor { CoreStore.assert( Thread.isMainThread, @@ -182,7 +182,7 @@ public extension DataStack { - parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections. - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. */ - public func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) { + public func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) { self.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses) } @@ -195,7 +195,7 @@ public extension DataStack { - parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections. - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. */ - public func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) { + public func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) { CoreStore.assert( Thread.isMainThread, diff --git a/Sources/DataStack+Querying.swift b/Sources/DataStack+Querying.swift index 94d06ac..e87b40d 100644 --- a/Sources/DataStack+Querying.swift +++ b/Sources/DataStack+Querying.swift @@ -84,7 +84,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s */ - public func fetchOne(_ from: From, _ fetchClauses: FetchClause...) -> T? { + public func fetchOne(_ from: From, _ fetchClauses: FetchClause...) -> T? { CoreStore.assert( Thread.isMainThread, @@ -100,7 +100,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s */ - public func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) -> T? { + public func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) -> T? { CoreStore.assert( Thread.isMainThread, @@ -116,7 +116,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s */ - public func fetchAll(_ from: From, _ fetchClauses: FetchClause...) -> [T]? { + public func fetchAll(_ from: From, _ fetchClauses: FetchClause...) -> [T]? { CoreStore.assert( Thread.isMainThread, @@ -132,7 +132,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s */ - public func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) -> [T]? { + public func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) -> [T]? { CoreStore.assert( Thread.isMainThread, @@ -148,7 +148,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s */ - public func fetchCount(_ from: From, _ fetchClauses: FetchClause...) -> Int? { + public func fetchCount(_ from: From, _ fetchClauses: FetchClause...) -> Int? { CoreStore.assert( Thread.isMainThread, @@ -164,7 +164,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s */ - public func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) -> Int? { + public func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) -> Int? { CoreStore.assert( Thread.isMainThread, @@ -180,7 +180,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s */ - public func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) -> NSManagedObjectID? { + public func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) -> NSManagedObjectID? { CoreStore.assert( Thread.isMainThread, @@ -196,7 +196,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s */ - public func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? { + public func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? { CoreStore.assert( Thread.isMainThread, @@ -212,7 +212,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s */ - public func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? { + public func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? { CoreStore.assert( Thread.isMainThread, @@ -228,7 +228,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s */ - public func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? { + public func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? { CoreStore.assert( Thread.isMainThread, @@ -250,7 +250,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> U? { + public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> U? { CoreStore.assert( Thread.isMainThread, @@ -269,7 +269,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> U? { + public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> U? { CoreStore.assert( Thread.isMainThread, @@ -288,7 +288,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> [[String: Any]]? { + public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> [[String: Any]]? { CoreStore.assert( Thread.isMainThread, @@ -307,7 +307,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> [[String: Any]]? { + public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> [[String: Any]]? { CoreStore.assert( Thread.isMainThread, diff --git a/Sources/DataStack+Transaction.swift b/Sources/DataStack+Transaction.swift index 52a09c7..d2ff361 100644 --- a/Sources/DataStack+Transaction.swift +++ b/Sources/DataStack+Transaction.swift @@ -211,9 +211,9 @@ public extension DataStack { } switch transaction.result { - case nil: return nil - case (let hasChanges, nil)?: return SaveResult(hasChanges: hasChanges) - case (_, let error?)?: return SaveResult(error) + case .none: return nil + case .some(let hasChanges, nil): return SaveResult(hasChanges: hasChanges) + case .some(_, let error?): return SaveResult(error) } } } diff --git a/Sources/FetchableSource.swift b/Sources/FetchableSource.swift index 5e0ac20..12f677a 100644 --- a/Sources/FetchableSource.swift +++ b/Sources/FetchableSource.swift @@ -73,7 +73,7 @@ public protocol FetchableSource: class { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s */ - func fetchOne(_ from: From, _ fetchClauses: FetchClause...) -> T? + func fetchOne(_ from: From, _ fetchClauses: FetchClause...) -> T? /** Fetches the first `DynamicObject` instance that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -82,7 +82,7 @@ public protocol FetchableSource: class { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s */ - func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) -> T? + func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) -> T? /** Fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -91,7 +91,7 @@ public protocol FetchableSource: class { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s */ - func fetchAll(_ from: From, _ fetchClauses: FetchClause...) -> [T]? + func fetchAll(_ from: From, _ fetchClauses: FetchClause...) -> [T]? /** Fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -100,7 +100,7 @@ public protocol FetchableSource: class { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s */ - func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) -> [T]? + func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) -> [T]? /** Fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -109,7 +109,7 @@ public protocol FetchableSource: class { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s */ - func fetchCount(_ from: From, _ fetchClauses: FetchClause...) -> Int? + func fetchCount(_ from: From, _ fetchClauses: FetchClause...) -> Int? /** Fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -118,7 +118,7 @@ public protocol FetchableSource: class { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the number `DynamicObject`s that satisfy the specified `FetchClause`s */ - func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) -> Int? + func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) -> Int? /** Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -127,7 +127,7 @@ public protocol FetchableSource: class { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s */ - func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) -> NSManagedObjectID? + func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) -> NSManagedObjectID? /** Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -136,7 +136,7 @@ public protocol FetchableSource: class { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s */ - func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? + func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? /** Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -145,7 +145,7 @@ public protocol FetchableSource: class { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s */ - func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? + func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? /** Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -154,7 +154,7 @@ public protocol FetchableSource: class { - parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s */ - func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? + func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? /** The internal `NSManagedObjectContext` managed by this `FetchableSource`. Using this context directly should typically be avoided, and is provided by CoreStore only for extremely specialized cases. diff --git a/Sources/From.swift b/Sources/From.swift index 0ccb9eb..6a746fa 100644 --- a/Sources/From.swift +++ b/Sources/From.swift @@ -139,7 +139,7 @@ public struct From { self.findPersistentStores = findPersistentStores } - internal func applyToFetchRequest(_ fetchRequest: NSFetchRequest, context: NSManagedObjectContext, applyAffectedStores: Bool = true) -> Bool { + internal func applyToFetchRequest(_ fetchRequest: NSFetchRequest, context: NSManagedObjectContext, applyAffectedStores: Bool = true) -> Bool { fetchRequest.entity = context.parentStack!.entityDescription(for: EntityIdentifier(self.entityClass))! guard applyAffectedStores else { @@ -157,7 +157,7 @@ public struct From { return false } - internal func applyAffectedStoresForFetchedRequest(_ fetchRequest: NSFetchRequest, context: NSManagedObjectContext) -> Bool { + internal func applyAffectedStoresForFetchedRequest(_ fetchRequest: NSFetchRequest, context: NSManagedObjectContext) -> Bool { let stores = self.findPersistentStores(context) fetchRequest.affectedStores = stores diff --git a/Sources/GroupBy.swift b/Sources/GroupBy.swift index 842b713..880bda8 100644 --- a/Sources/GroupBy.swift +++ b/Sources/GroupBy.swift @@ -71,7 +71,7 @@ public struct GroupBy: QueryClause, Hashable { // MARK: QueryClause - public func applyToFetchRequest(_ fetchRequest: NSFetchRequest) { + public func applyToFetchRequest(_ fetchRequest: NSFetchRequest) { if let keyPaths = fetchRequest.propertiesToGroupBy as? [String], keyPaths != self.keyPaths { diff --git a/Sources/ImportableUniqueObject.swift b/Sources/ImportableUniqueObject.swift index 7ced67e..05dbbfd 100644 --- a/Sources/ImportableUniqueObject.swift +++ b/Sources/ImportableUniqueObject.swift @@ -55,11 +55,6 @@ import CoreData */ public protocol ImportableUniqueObject: ImportableObject { - /** - The data type for the import source. This is most commonly an json type, `NSDictionary`, or another external source such as `NSUserDefaults`. - */ - associatedtype ImportSource - /** The data type for the entity's unique ID attribute */ @@ -125,6 +120,26 @@ public protocol ImportableUniqueObject: ImportableObject { public extension ImportableUniqueObject { + var uniqueIDValue: UniqueIDType { + + get { + + return self.cs_toRaw().getValue( + forKvcKey: type(of: self).uniqueIDKeyPath, + didGetValue: { UniqueIDType.cs_fromImportableNativeType($0 as! UniqueIDType.ImportableNativeType)! } + ) + } + set { + + self.cs_toRaw() + .setValue( + newValue, + forKvcKey: type(of: self).uniqueIDKeyPath, + willSetValue: { ($0.cs_toImportableNativeType() as! CoreDataNativeType) } + ) + } + } + static func shouldInsert(from source: ImportSource, in transaction: BaseDataTransaction) -> Bool { return Self.shouldUpdate(from: source, in: transaction) @@ -173,29 +188,3 @@ public extension ImportableUniqueObject { try self.update(from: source, in: transaction) } } - - -// MARK: - ImportableUniqueObject (Default Implementations) - -public extension ImportableUniqueObject where Self: DynamicObject { - - var uniqueIDValue: UniqueIDType { - - get { - - return self.cs_toRaw().getValue( - forKvcKey: type(of: self).uniqueIDKeyPath, - didGetValue: { UniqueIDType.cs_fromImportableNativeType($0 as! UniqueIDType.ImportableNativeType)! } - ) - } - set { - - self.cs_toRaw() - .setValue( - newValue, - forKvcKey: type(of: self).uniqueIDKeyPath, - willSetValue: { ($0.cs_toImportableNativeType() as! CoreDataNativeType) } - ) - } - } -} diff --git a/Sources/Into.swift b/Sources/Into.swift index ec070d6..8730af9 100644 --- a/Sources/Into.swift +++ b/Sources/Into.swift @@ -103,7 +103,7 @@ public struct Into: Hashable { // MARK: Equatable - public static func == (lhs: Into, rhs: Into) -> Bool { + public static func == (lhs: Into, rhs: Into) -> Bool { return lhs.entityClass == rhs.entityClass && lhs.configuration == rhs.configuration diff --git a/Sources/ListMonitor.swift b/Sources/ListMonitor.swift index 39536f4..2be4277 100644 --- a/Sources/ListMonitor.swift +++ b/Sources/ListMonitor.swift @@ -600,7 +600,7 @@ public final class ListMonitor: Hashable { return lhs.fetchedResultsController === rhs.fetchedResultsController } - public static func == (lhs: ListMonitor, rhs: ListMonitor) -> Bool { + public static func == (lhs: ListMonitor, rhs: ListMonitor) -> Bool { return lhs.fetchedResultsController === rhs.fetchedResultsController } @@ -610,7 +610,7 @@ public final class ListMonitor: Hashable { return lhs.fetchedResultsController === rhs.fetchedResultsController } - public static func ~= (lhs: ListMonitor, rhs: ListMonitor) -> Bool { + public static func ~= (lhs: ListMonitor, rhs: ListMonitor) -> Bool { return lhs.fetchedResultsController === rhs.fetchedResultsController } diff --git a/Sources/MigrationChain.swift b/Sources/MigrationChain.swift index 790749c..3f46dd8 100644 --- a/Sources/MigrationChain.swift +++ b/Sources/MigrationChain.swift @@ -87,7 +87,7 @@ public struct MigrationChain: ExpressibleByNilLiteral, ExpressibleByStringLitera /** Initializes the `MigrationChain` with a linear order of versions, which becomes the order of the `DataStack`'s progressive migrations. */ - public init(_ elements: T) where T.Iterator.Element == String, T.SubSequence.Iterator.Element == String, T.Index: Comparable { + public init(_ elements: T) where T.Iterator.Element == String { CoreStore.assert(Set(elements).count == Array(elements).count, "\(cs_typeName(MigrationChain.self))'s migration chain could not be created due to duplicate version strings.") diff --git a/Sources/NSManagedObjectContext+Querying.swift b/Sources/NSManagedObjectContext+Querying.swift index 084e331..11e58e6 100644 --- a/Sources/NSManagedObjectContext+Querying.swift +++ b/Sources/NSManagedObjectContext+Querying.swift @@ -101,13 +101,13 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { } @nonobjc - public func fetchOne(_ from: From, _ fetchClauses: FetchClause...) -> T? { + public func fetchOne(_ from: From, _ fetchClauses: FetchClause...) -> T? { return self.fetchOne(from, fetchClauses) } @nonobjc - public func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) -> T? { + public func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) -> T? { let fetchRequest = CoreStoreFetchRequest() let storeFound = from.applyToFetchRequest(fetchRequest, context: self) @@ -124,13 +124,13 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { } @nonobjc - public func fetchAll(_ from: From, _ fetchClauses: FetchClause...) -> [T]? { + public func fetchAll(_ from: From, _ fetchClauses: FetchClause...) -> [T]? { return self.fetchAll(from, fetchClauses) } @nonobjc - public func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) -> [T]? { + public func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) -> [T]? { let fetchRequest = CoreStoreFetchRequest() let storeFound = from.applyToFetchRequest(fetchRequest, context: self) @@ -148,13 +148,13 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { } @nonobjc - public func fetchCount(_ from: From, _ fetchClauses: FetchClause...) -> Int? { + public func fetchCount(_ from: From, _ fetchClauses: FetchClause...) -> Int? { return self.fetchCount(from, fetchClauses) } @nonobjc - public func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) -> Int? { + public func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) -> Int? { let fetchRequest = CoreStoreFetchRequest() let storeFound = from.applyToFetchRequest(fetchRequest, context: self) @@ -168,13 +168,13 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { } @nonobjc - public func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) -> NSManagedObjectID? { + public func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) -> NSManagedObjectID? { return self.fetchObjectID(from, fetchClauses) } @nonobjc - public func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? { + public func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? { let fetchRequest = CoreStoreFetchRequest() let storeFound = from.applyToFetchRequest(fetchRequest, context: self) @@ -191,13 +191,13 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { } @nonobjc - public func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? { + public func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? { return self.fetchObjectIDs(from, fetchClauses) } @nonobjc - public func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? { + public func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? { let fetchRequest = CoreStoreFetchRequest() let storeFound = from.applyToFetchRequest(fetchRequest, context: self) @@ -244,13 +244,13 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { // MARK: QueryableSource @nonobjc - public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> U? { + public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> U? { return self.queryValue(from, selectClause, queryClauses) } @nonobjc - public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> U? { + public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> U? { let fetchRequest = CoreStoreFetchRequest() let storeFound = from.applyToFetchRequest(fetchRequest, context: self) @@ -269,13 +269,13 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { } @nonobjc - public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> [[String: Any]]? { + public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> [[String: Any]]? { return self.queryAttributes(from, selectClause, queryClauses) } @nonobjc - public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> [[String: Any]]? { + public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> [[String: Any]]? { let fetchRequest = CoreStoreFetchRequest() let storeFound = from.applyToFetchRequest(fetchRequest, context: self) @@ -305,13 +305,13 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { // MARK: Deleting @nonobjc - internal func deleteAll(_ from: From, _ deleteClauses: DeleteClause...) -> Int? { + internal func deleteAll(_ from: From, _ deleteClauses: DeleteClause...) -> Int? { return self.deleteAll(from, deleteClauses) } @nonobjc - internal func deleteAll(_ from: From, _ deleteClauses: [DeleteClause]) -> Int? { + internal func deleteAll(_ from: From, _ deleteClauses: [DeleteClause]) -> Int? { let fetchRequest = CoreStoreFetchRequest() let storeFound = from.applyToFetchRequest(fetchRequest, context: self) diff --git a/Sources/ObjectMonitor.swift b/Sources/ObjectMonitor.swift index e32a177..b2d8db1 100644 --- a/Sources/ObjectMonitor.swift +++ b/Sources/ObjectMonitor.swift @@ -132,7 +132,7 @@ public final class ObjectMonitor: Equatable { return lhs === rhs } - public static func == (lhs: ObjectMonitor, rhs: ObjectMonitor) -> Bool { + public static func == (lhs: ObjectMonitor, rhs: ObjectMonitor) -> Bool { return lhs.fetchedResultsController === rhs.fetchedResultsController } @@ -142,7 +142,7 @@ public final class ObjectMonitor: Equatable { return lhs === rhs } - public static func ~= (lhs: ObjectMonitor, rhs: ObjectMonitor) -> Bool { + public static func ~= (lhs: ObjectMonitor, rhs: ObjectMonitor) -> Bool { return lhs.fetchedResultsController === rhs.fetchedResultsController } diff --git a/Sources/OrderBy.swift b/Sources/OrderBy.swift index 692a8fe..e79fafa 100644 --- a/Sources/OrderBy.swift +++ b/Sources/OrderBy.swift @@ -143,7 +143,7 @@ public struct OrderBy: FetchClause, QueryClause, DeleteClause, Hashable { // MARK: FetchClause, QueryClause, DeleteClause - public func applyToFetchRequest(_ fetchRequest: NSFetchRequest) { + public func applyToFetchRequest(_ fetchRequest: NSFetchRequest) { if let sortDescriptors = fetchRequest.sortDescriptors, sortDescriptors != self.sortDescriptors { diff --git a/Sources/QueryableAttributeType.swift b/Sources/QueryableAttributeType.swift index c0c5dba..974bd06 100644 --- a/Sources/QueryableAttributeType.swift +++ b/Sources/QueryableAttributeType.swift @@ -434,12 +434,20 @@ extension NSNull: QueryableAttributeType { public typealias QueryableNativeType = NSNull - public static let cs_rawAttributeType: NSAttributeType = .undefinedAttributeType + public class var cs_rawAttributeType: NSAttributeType { + + return .undefinedAttributeType + } @nonobjc @inline(__always) public static func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? { - return self.init() + @inline(__always) + func forceCast(_ value: Any) -> T? { + + return value as? T + } + return forceCast(value) } @nonobjc @inline(__always) diff --git a/Sources/QueryableSource.swift b/Sources/QueryableSource.swift index 303c63c..4b40a42 100644 --- a/Sources/QueryableSource.swift +++ b/Sources/QueryableSource.swift @@ -44,7 +44,7 @@ public protocol QueryableSource: class { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> U? + func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> U? /** Queries aggregate values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. @@ -56,7 +56,7 @@ public protocol QueryableSource: class { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> U? + func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> U? /** Queries a dictionary of attribute values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. @@ -68,7 +68,7 @@ public protocol QueryableSource: class { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> [[String: Any]]? + func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> [[String: Any]]? /** Queries a dictionary of attribute values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. @@ -80,7 +80,7 @@ public protocol QueryableSource: class { - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select` parameter. */ - func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> [[String: Any]]? + func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) -> [[String: Any]]? /** The internal `NSManagedObjectContext` managed by this `QueryableSource`. Using this context directly should typically be avoided, and is provided by CoreStore only for extremely specialized cases. diff --git a/Sources/Relationship.swift b/Sources/Relationship.swift index 88606be..365ae93 100644 --- a/Sources/Relationship.swift +++ b/Sources/Relationship.swift @@ -860,7 +860,7 @@ extension RelationshipContainer.ToManyOrdered: RandomAccessCollection { public func makeIterator() -> Iterator { - let iterator = self.nativeValue.makeIterator() + var iterator = self.nativeValue.makeIterator() return AnyIterator({ iterator.next().flatMap({ D.cs_fromRaw(object: $0 as! NSManagedObject) }) }) } @@ -915,7 +915,7 @@ extension RelationshipContainer.ToManyUnordered: Sequence { public func makeIterator() -> Iterator { - let iterator = self.nativeValue.makeIterator() + var iterator = self.nativeValue.makeIterator() return AnyIterator({ iterator.next().flatMap({ D.cs_fromRaw(object: $0 as! NSManagedObject) }) }) } } @@ -953,7 +953,7 @@ extension RelationshipContainer.ToOne { dog.master.value = anotherDog.master.value ``` */ - public static func .= (_ relationship: RelationshipContainer.ToOne, _ relationship2: RelationshipContainer.ToOne) { + public static func .= (_ relationship: RelationshipContainer.ToOne, _ relationship2: RelationshipContainer.ToOne) { relationship.nativeValue = relationship2.nativeValue } @@ -998,7 +998,7 @@ extension RelationshipContainer.ToOne { if dog.master.value == person { ... } ``` */ - public static func .== (_ relationship: RelationshipContainer.ToOne, _ relationship2: RelationshipContainer.ToOne) -> Bool { + public static func .== (_ relationship: RelationshipContainer.ToOne, _ relationship2: RelationshipContainer.ToOne) -> Bool { return relationship.nativeValue == relationship2.nativeValue } @@ -1031,7 +1031,7 @@ extension RelationshipContainer.ToManyOrdered { person.pets.value = anotherPerson.pets.value ``` */ - public static func .= (_ relationship: RelationshipContainer.ToManyOrdered, _ relationship2: RelationshipContainer.ToManyOrdered) { + public static func .= (_ relationship: RelationshipContainer.ToManyOrdered, _ relationship2: RelationshipContainer.ToManyOrdered) { relationship.nativeValue = relationship2.nativeValue } @@ -1082,7 +1082,7 @@ extension RelationshipContainer.ToManyOrdered { if person.pets.value == anotherPerson.pets.value { ... } ``` */ - public static func .== (_ relationship: RelationshipContainer.ToManyOrdered, _ relationship2: RelationshipContainer.ToManyOrdered) -> Bool { + public static func .== (_ relationship: RelationshipContainer.ToManyOrdered, _ relationship2: RelationshipContainer.ToManyOrdered) -> Bool { return relationship.nativeValue == relationship2.nativeValue } @@ -1115,7 +1115,7 @@ extension RelationshipContainer.ToManyUnordered { person.pets.value = anotherPerson.pets.value ``` */ - public static func .= (_ relationship: RelationshipContainer.ToManyUnordered, _ relationship2: RelationshipContainer.ToManyUnordered) { + public static func .= (_ relationship: RelationshipContainer.ToManyUnordered, _ relationship2: RelationshipContainer.ToManyUnordered) { relationship.nativeValue = relationship2.nativeValue } @@ -1130,7 +1130,7 @@ extension RelationshipContainer.ToManyUnordered { person.pets.value = anotherPerson.pets.value ``` */ - public static func .= (_ relationship: RelationshipContainer.ToManyUnordered, _ relationship2: RelationshipContainer.ToManyOrdered) { + public static func .= (_ relationship: RelationshipContainer.ToManyUnordered, _ relationship2: RelationshipContainer.ToManyOrdered) { relationship.nativeValue = NSSet(set: relationship2.nativeValue.set) } @@ -1175,7 +1175,7 @@ extension RelationshipContainer.ToManyUnordered { if person.pets.value == anotherPerson.pets.value { ... } ``` */ - public static func .== (_ relationship: RelationshipContainer.ToManyUnordered, _ relationship2: RelationshipContainer.ToManyUnordered) -> Bool { + public static func .== (_ relationship: RelationshipContainer.ToManyUnordered, _ relationship2: RelationshipContainer.ToManyUnordered) -> Bool { return relationship.nativeValue.isEqual(relationship2.nativeValue) } diff --git a/Sources/Select.swift b/Sources/Select.swift index 6b2e8c4..468d5e5 100644 --- a/Sources/Select.swift +++ b/Sources/Select.swift @@ -339,7 +339,7 @@ public struct Select: Hashable { // MARK: Equatable - public static func == (lhs: Select, rhs: Select) -> Bool { + public static func == (lhs: Select, rhs: Select) -> Bool { return lhs.selectTerms == rhs.selectTerms } diff --git a/Sources/SetupResult.swift b/Sources/SetupResult.swift index 545412a..26be478 100644 --- a/Sources/SetupResult.swift +++ b/Sources/SetupResult.swift @@ -88,7 +88,7 @@ public enum SetupResult: Hashable { // MARK: Equatable - public static func == (lhs: SetupResult, rhs: SetupResult) -> Bool { + public static func == (lhs: SetupResult, rhs: SetupResult) -> Bool { switch (lhs, rhs) { diff --git a/Sources/SynchronousDataTransaction.swift b/Sources/SynchronousDataTransaction.swift index d9a3f92..0957a2d 100644 --- a/Sources/SynchronousDataTransaction.swift +++ b/Sources/SynchronousDataTransaction.swift @@ -55,7 +55,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction { - parameter into: the `Into` clause indicating the destination `NSManagedObject` or `CoreStoreObject` entity type and the destination configuration - returns: a new `NSManagedObject` or `CoreStoreObject` instance of the specified entity type. */ - public override func create(_ into: Into) -> T { + public override func create(_ into: Into) -> T { CoreStore.assert( !self.isCommitted, @@ -88,7 +88,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction { - parameter objectID: the `NSManagedObjectID` for the object to be edited - returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`. */ - public override func edit(_ into: Into, _ objectID: NSManagedObjectID) -> T? { + public override func edit(_ into: Into, _ objectID: NSManagedObjectID) -> T? { CoreStore.assert( !self.isCommitted, @@ -230,9 +230,9 @@ public final class SynchronousDataTransaction: BaseDataTransaction { } switch childTransaction.result { - case nil: return nil - case (let hasChanges, nil)?: return SaveResult(hasChanges: hasChanges) - case (_, let error?)?: return SaveResult(error) + case .none: return nil + case .some(let hasChanges, nil): return SaveResult(hasChanges: hasChanges) + case .some(_, let error?): return SaveResult(error) } } } diff --git a/Sources/Tweak.swift b/Sources/Tweak.swift index 108be78..17e3b0a 100644 --- a/Sources/Tweak.swift +++ b/Sources/Tweak.swift @@ -63,7 +63,7 @@ public struct Tweak: FetchClause, QueryClause, DeleteClause { // MARK: FetchClause, QueryClause, DeleteClause - public func applyToFetchRequest(_ fetchRequest: NSFetchRequest) { + public func applyToFetchRequest(_ fetchRequest: NSFetchRequest) { self.closure(fetchRequest as! NSFetchRequest) } diff --git a/Sources/UnsafeDataTransaction+Observing.swift b/Sources/UnsafeDataTransaction+Observing.swift index 3a85332..02cbd03 100644 --- a/Sources/UnsafeDataTransaction+Observing.swift +++ b/Sources/UnsafeDataTransaction+Observing.swift @@ -38,7 +38,7 @@ public extension UnsafeDataTransaction { - parameter object: the `DynamicObject` to observe changes from - returns: a `ObjectMonitor` that monitors changes to `object` */ - public func monitorObject(_ object: T) -> ObjectMonitor { + public func monitorObject(_ object: T) -> ObjectMonitor { return ObjectMonitor( unsafeTransaction: self, @@ -53,7 +53,7 @@ public extension UnsafeDataTransaction { - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: a `ListMonitor` instance that monitors changes to the list */ - public func monitorList(_ from: From, _ fetchClauses: FetchClause...) -> ListMonitor { + public func monitorList(_ from: From, _ fetchClauses: FetchClause...) -> ListMonitor { return self.monitorList(from, fetchClauses) } @@ -65,7 +65,7 @@ public extension UnsafeDataTransaction { - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: a `ListMonitor` instance that monitors changes to the list */ - public func monitorList(_ from: From, _ fetchClauses: [FetchClause]) -> ListMonitor { + public func monitorList(_ from: From, _ fetchClauses: [FetchClause]) -> ListMonitor { CoreStore.assert( fetchClauses.filter { $0 is OrderBy }.count > 0, @@ -90,7 +90,7 @@ public extension UnsafeDataTransaction { - parameter from: a `From` clause indicating the entity type - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. */ - public func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: FetchClause...) { + public func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: FetchClause...) { self.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses) } @@ -102,7 +102,7 @@ public extension UnsafeDataTransaction { - parameter from: a `From` clause indicating the entity type - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. */ - public func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: [FetchClause]) { + public func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ fetchClauses: [FetchClause]) { CoreStore.assert( fetchClauses.filter { $0 is OrderBy }.count > 0, @@ -129,7 +129,7 @@ public extension UnsafeDataTransaction { - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: a `ListMonitor` instance that monitors changes to the list */ - public func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor { + public func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor { return self.monitorSectionedList(from, sectionBy, fetchClauses) } @@ -142,7 +142,7 @@ public extension UnsafeDataTransaction { - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. - returns: a `ListMonitor` instance that monitors changes to the list */ - public func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor { + public func monitorSectionedList(_ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor { CoreStore.assert( fetchClauses.filter { $0 is OrderBy }.count > 0, @@ -168,7 +168,7 @@ public extension UnsafeDataTransaction { - parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections. - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. */ - public func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) { + public func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) { self.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses) } @@ -181,7 +181,7 @@ public extension UnsafeDataTransaction { - parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections. - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses. */ - public func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) { + public func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ from: From, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) { CoreStore.assert( fetchClauses.filter { $0 is OrderBy }.count > 0, diff --git a/Sources/Value.swift b/Sources/Value.swift index 17b9941..72f94ce 100644 --- a/Sources/Value.swift +++ b/Sources/Value.swift @@ -733,7 +733,7 @@ extension ValueContainer.Required { animal.species.value = anotherAnimal.species.value ``` */ - public static func .= (_ property: ValueContainer.Required, _ property2: ValueContainer.Required) { + public static func .= (_ property: ValueContainer.Required, _ property2: ValueContainer.Required) { property.value = property2.value } @@ -826,7 +826,7 @@ extension ValueContainer.Optional { animal.nickname.value = anotherAnimal.nickname.value ``` */ - public static func .= (_ property: ValueContainer.Optional, _ property2: ValueContainer.Optional) { + public static func .= (_ property: ValueContainer.Optional, _ property2: ValueContainer.Optional) { property.value = property2.value } @@ -841,7 +841,7 @@ extension ValueContainer.Optional { animal.nickname.value = anotherAnimal.species.value ``` */ - public static func .= (_ property: ValueContainer.Optional, _ property2: ValueContainer.Required) { + public static func .= (_ property: ValueContainer.Optional, _ property2: ValueContainer.Required) { property.value = property2.value } @@ -934,7 +934,7 @@ extension TransformableContainer.Required { animal.nickname.value = anotherAnimal.species.value ``` */ - public static func .= (_ property: TransformableContainer.Required, _ property2: TransformableContainer.Required) { + public static func .= (_ property: TransformableContainer.Required, _ property2: TransformableContainer.Required) { property.value = property2.value } @@ -967,7 +967,7 @@ extension TransformableContainer.Optional { animal.color.value = anotherAnimal.color.value ``` */ - public static func .= (_ property: TransformableContainer.Optional, _ property2: TransformableContainer.Optional) { + public static func .= (_ property: TransformableContainer.Optional, _ property2: TransformableContainer.Optional) { property.value = property2.value } @@ -982,7 +982,7 @@ extension TransformableContainer.Optional { animal.color.value = anotherAnimal.color.value ``` */ - public static func .= (_ property: TransformableContainer.Optional, _ property2: TransformableContainer.Required) { + public static func .= (_ property: TransformableContainer.Optional, _ property2: TransformableContainer.Required) { property.value = property2.value } diff --git a/Sources/Where.swift b/Sources/Where.swift index 2571238..76a095b 100644 --- a/Sources/Where.swift +++ b/Sources/Where.swift @@ -187,7 +187,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable { // MARK: FetchClause, QueryClause, DeleteClause - public func applyToFetchRequest(_ fetchRequest: NSFetchRequest) { + public func applyToFetchRequest(_ fetchRequest: NSFetchRequest) { if let predicate = fetchRequest.predicate, predicate != self.predicate {