From 57778315653f1f3583a73c3ad140732eec8329f2 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Fri, 11 Jan 2019 19:52:12 +0900 Subject: [PATCH 1/4] WIP: make fetching methods throwable --- Sources/BaseDataTransaction+Querying.swift | 36 ++--- Sources/CSError.swift | 8 ++ Sources/CSListMonitor.swift | 20 +-- Sources/CoreStore+Observing.swift | 7 +- Sources/CoreStore+Querying.swift | 36 ++--- Sources/CoreStoreError.swift | 24 ++++ .../CoreStoreFetchedResultsController.swift | 14 +- Sources/DataStack+Observing.swift | 7 +- Sources/DataStack+Querying.swift | 36 ++--- Sources/FetchableSource.swift | 18 +-- Sources/From.swift | 35 +++-- Sources/ListMonitor.swift | 127 ++++++++++++++---- .../NSManagedObjectContext+ObjectiveC.swift | 60 +++------ Sources/NSManagedObjectContext+Querying.swift | 95 ++++++------- Sources/UnsafeDataTransaction+Observing.swift | 21 ++- Sources/Where.swift | 8 +- 16 files changed, 326 insertions(+), 226 deletions(-) diff --git a/Sources/BaseDataTransaction+Querying.swift b/Sources/BaseDataTransaction+Querying.swift index 39b05bd..4d712c5 100644 --- a/Sources/BaseDataTransaction+Querying.swift +++ b/Sources/BaseDataTransaction+Querying.swift @@ -138,13 +138,13 @@ 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...) -> D? { + public func fetchOne(_ from: From, _ fetchClauses: FetchClause...) throws -> D? { CoreStore.assert( self.isRunningInAllowedQueue(), "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) - return self.context.fetchOne(from, fetchClauses) + return try self.context.fetchOne(from, fetchClauses) } /** @@ -154,13 +154,13 @@ 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]) -> D? { + public func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) throws -> D? { CoreStore.assert( self.isRunningInAllowedQueue(), "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) - return self.context.fetchOne(from, fetchClauses) + return try self.context.fetchOne(from, fetchClauses) } /** @@ -175,13 +175,13 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - returns: the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType` */ - public func fetchOne(_ clauseChain: B) -> B.ObjectType? { + public func fetchOne(_ clauseChain: B) throws -> B.ObjectType? { CoreStore.assert( self.isRunningInAllowedQueue(), "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) - return self.context.fetchOne(clauseChain) + return try self.context.fetchOne(clauseChain) } /** @@ -191,13 +191,13 @@ 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...) -> [D]? { + public func fetchAll(_ from: From, _ fetchClauses: FetchClause...) throws -> [D] { CoreStore.assert( self.isRunningInAllowedQueue(), "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) - return self.context.fetchAll(from, fetchClauses) + return try self.context.fetchAll(from, fetchClauses) } /** @@ -207,13 +207,13 @@ 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]) -> [D]? { + public func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) throws -> [D] { CoreStore.assert( self.isRunningInAllowedQueue(), "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) - return self.context.fetchAll(from, fetchClauses) + return try self.context.fetchAll(from, fetchClauses) } /** @@ -228,13 +228,13 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - returns: all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType` */ - public func fetchAll(_ clauseChain: B) -> [B.ObjectType]? { + public func fetchAll(_ clauseChain: B) throws -> [B.ObjectType] { CoreStore.assert( self.isRunningInAllowedQueue(), "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) - return self.context.fetchAll(clauseChain) + return try self.context.fetchAll(clauseChain) } /** @@ -244,13 +244,13 @@ 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...) throws -> Int { CoreStore.assert( self.isRunningInAllowedQueue(), "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) - return self.context.fetchCount(from, fetchClauses) + return try self.context.fetchCount(from, fetchClauses) } /** @@ -260,13 +260,13 @@ 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]) throws -> Int { CoreStore.assert( self.isRunningInAllowedQueue(), "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) - return self.context.fetchCount(from, fetchClauses) + return try self.context.fetchCount(from, fetchClauses) } /** @@ -281,13 +281,13 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - returns: the number `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` */ - public func fetchCount(_ clauseChain: B) -> Int? { + public func fetchCount(_ clauseChain: B) throws -> Int { CoreStore.assert( self.isRunningInAllowedQueue(), "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) - return self.context.fetchCount(clauseChain) + return try self.context.fetchCount(clauseChain) } /** diff --git a/Sources/CSError.swift b/Sources/CSError.swift index 9fb1feb..84908ff 100644 --- a/Sources/CSError.swift +++ b/Sources/CSError.swift @@ -247,6 +247,14 @@ extension CoreStoreError: CoreStoreSwiftType, _ObjectiveCBridgeableError { case .userCancelled: self = .userCancelled + + case .persistentStoreNotFound: + guard let entity = info["entity"] as? DynamicObject.Type else { + + self = .unknown + return + } + self = .persistentStoreNotFound(entity: entity) } } } diff --git a/Sources/CSListMonitor.swift b/Sources/CSListMonitor.swift index d639067..44097f6 100644 --- a/Sources/CSListMonitor.swift +++ b/Sources/CSListMonitor.swift @@ -132,7 +132,7 @@ public final class CSListMonitor: NSObject { @objc public func hasObjectsInSection(_ section: Int) -> Bool { - return self.bridgeToSwift.hasObjectsInSection(section) + return self.bridgeToSwift.hasObjects(in: section) } /** @@ -155,7 +155,7 @@ public final class CSListMonitor: NSObject { @objc public func objectsInSection(_ section: Int) -> [NSManagedObject] { - return self.bridgeToSwift.objectsInSection(section) + return self.bridgeToSwift.objects(in: section) } /** @@ -167,7 +167,7 @@ public final class CSListMonitor: NSObject { @objc public func objectsInSafeSection(safeSectionIndex section: Int) -> [NSManagedObject]? { - return self.bridgeToSwift.objectsInSection(safeSectionIndex: section) + return self.bridgeToSwift.objects(safelyIn: section) } /** @@ -201,7 +201,7 @@ public final class CSListMonitor: NSObject { @objc public func numberOfObjectsInSection(_ section: Int) -> Int { - return self.bridgeToSwift.numberOfObjectsInSection(section) + return self.bridgeToSwift.numberOfObjects(in: section) } /** @@ -214,7 +214,7 @@ public final class CSListMonitor: NSObject { public func numberOfObjectsInSafeSection(safeSectionIndex section: Int) -> NSNumber? { return self.bridgeToSwift - .numberOfObjectsInSection(safeSectionIndex: section) + .numberOfObjects(safelyIn: section) .flatMap { NSNumber(value: $0) } } @@ -227,7 +227,7 @@ public final class CSListMonitor: NSObject { @objc public func sectionInfoAtIndex(_ section: Int) -> NSFetchedResultsSectionInfo { - return self.bridgeToSwift.sectionInfoAtIndex(section) + return self.bridgeToSwift.sectionInfo(at: section) } /** @@ -239,7 +239,7 @@ public final class CSListMonitor: NSObject { @objc public func sectionInfoAtSafeSectionIndex(safeSectionIndex section: Int) -> NSFetchedResultsSectionInfo? { - return self.bridgeToSwift.sectionInfoAtIndex(safeSectionIndex: section) + return self.bridgeToSwift.sectionInfo(safelyAt: section) } /** @@ -263,7 +263,7 @@ public final class CSListMonitor: NSObject { @objc public func targetSectionForSectionIndexTitle(title: String, index: Int) -> Int { - return self.bridgeToSwift.targetSectionForSectionIndex(title: title, index: index) + return self.bridgeToSwift.targetSection(forSectionIndexTitle: title, at: index) } /** @@ -287,7 +287,7 @@ public final class CSListMonitor: NSObject { public func indexOf(_ object: NSManagedObject) -> NSNumber? { return self.bridgeToSwift - .indexOf(object) + .index(of: object) .flatMap { NSNumber(value: $0) } } @@ -300,7 +300,7 @@ public final class CSListMonitor: NSObject { @objc public func indexPathOf(_ object: NSManagedObject) -> IndexPath? { - return self.bridgeToSwift.indexPathOf(object) + return self.bridgeToSwift.indexPath(of: object) } diff --git a/Sources/CoreStore+Observing.swift b/Sources/CoreStore+Observing.swift index e594c26..ca11967 100644 --- a/Sources/CoreStore+Observing.swift +++ b/Sources/CoreStore+Observing.swift @@ -113,7 +113,7 @@ public extension CoreStore { ``` CoreStore.monitorList( - { (monitor) in + createAsynchronously: { (monitor) in self.monitor = monitor }, From() @@ -123,7 +123,6 @@ public extension CoreStore { ``` - parameter createAsynchronously: the closure that receives the created `ListMonitor` instance - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - - returns: a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` */ public static func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ clauseChain: B) { @@ -212,7 +211,7 @@ public extension CoreStore { Asynchronously creates a `ListMonitor` for a sectioned list of `DynamicObject`s that satisfy the specified `SectionMonitorBuilderType` built from a chain of clauses. ``` CoreStore.monitorSectionedList( - { (monitor) in + createAsynchronously: { (monitor) in self.monitor = monitor }, From() @@ -221,8 +220,8 @@ public extension CoreStore { .orderBy(.ascending(\.age)) ) ``` + - parameter createAsynchronously: the closure that receives the created `ListMonitor` instance - parameter clauseChain: a `SectionMonitorBuilderType` built from a chain of clauses - - returns: a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified `SectionMonitorBuilderType` */ public static func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ clauseChain: B) { diff --git a/Sources/CoreStore+Querying.swift b/Sources/CoreStore+Querying.swift index 66f9f7b..2976a28 100644 --- a/Sources/CoreStore+Querying.swift +++ b/Sources/CoreStore+Querying.swift @@ -82,9 +82,9 @@ 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...) -> D? { + public static func fetchOne(_ from: From, _ fetchClauses: FetchClause...) throws -> D? { - return self.defaultStack.fetchOne(from, fetchClauses) + return try self.defaultStack.fetchOne(from, fetchClauses) } /** @@ -94,9 +94,9 @@ 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]) -> D? { + public static func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) throws -> D? { - return self.defaultStack.fetchOne(from, fetchClauses) + return try self.defaultStack.fetchOne(from, fetchClauses) } /** @@ -111,9 +111,9 @@ public extension CoreStore { - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - returns: the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType` */ - public static func fetchOne(_ clauseChain: B) -> B.ObjectType? { + public static func fetchOne(_ clauseChain: B) throws -> B.ObjectType? { - return self.defaultStack.fetchOne(clauseChain) + return try self.defaultStack.fetchOne(clauseChain) } /** @@ -123,9 +123,9 @@ 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...) -> [D]? { + public static func fetchAll(_ from: From, _ fetchClauses: FetchClause...) throws -> [D] { - return self.defaultStack.fetchAll(from, fetchClauses) + return try self.defaultStack.fetchAll(from, fetchClauses) } /** @@ -135,9 +135,9 @@ 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]) -> [D]? { + public static func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) throws -> [D] { - return self.defaultStack.fetchAll(from, fetchClauses) + return try self.defaultStack.fetchAll(from, fetchClauses) } /** @@ -152,9 +152,9 @@ public extension CoreStore { - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - returns: all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType` */ - public static func fetchAll(_ clauseChain: B) -> [B.ObjectType]? { + public static func fetchAll(_ clauseChain: B) throws -> [B.ObjectType] { - return self.defaultStack.fetchAll(clauseChain) + return try self.defaultStack.fetchAll(clauseChain) } /** @@ -164,9 +164,9 @@ 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...) throws -> Int { - return self.defaultStack.fetchCount(from, fetchClauses) + return try self.defaultStack.fetchCount(from, fetchClauses) } /** @@ -176,9 +176,9 @@ 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]) throws -> Int { - return self.defaultStack.fetchCount(from, fetchClauses) + return try self.defaultStack.fetchCount(from, fetchClauses) } /** @@ -193,9 +193,9 @@ public extension CoreStore { - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - returns: the number `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` */ - public static func fetchCount(_ clauseChain: B) -> Int? { + public static func fetchCount(_ clauseChain: B) throws -> Int { - return self.defaultStack.fetchCount(clauseChain) + return try self.defaultStack.fetchCount(clauseChain) } /** diff --git a/Sources/CoreStoreError.swift b/Sources/CoreStoreError.swift index 9dec792..67e09f9 100644 --- a/Sources/CoreStoreError.swift +++ b/Sources/CoreStoreError.swift @@ -73,6 +73,11 @@ public enum CoreStoreError: Error, CustomNSError, Hashable { The transaction was cancelled by the user. */ case userCancelled + + /** + Attempted to perform a fetch but could not find any related persistent store. + */ + case persistentStoreNotFound(entity: DynamicObject.Type) // MARK: CustomNSError @@ -109,6 +114,9 @@ public enum CoreStoreError: Error, CustomNSError, Hashable { case .userCancelled: return CoreStoreErrorCode.userCancelled.rawValue + + case .persistentStoreNotFound: + return CoreStoreErrorCode.persistentStoreNotFound.rawValue } } @@ -154,6 +162,11 @@ public enum CoreStoreError: Error, CustomNSError, Hashable { case .userCancelled: return [:] + + case .persistentStoreNotFound(let entity): + return [ + "entity": entity + ] } } @@ -195,6 +208,9 @@ public enum CoreStoreError: Error, CustomNSError, Hashable { case (.userCancelled, .userCancelled): return true + + case (.persistentStoreNotFound(let entity1), .persistentStoreNotFound(let entity2)): + return entity1 == entity2 default: return false @@ -233,6 +249,9 @@ public enum CoreStoreError: Error, CustomNSError, Hashable { case .userError(let error): hasher.combine(error as NSError) + case .persistentStoreNotFound(let entity): + hasher.combine(ObjectIdentifier(entity)) + case .userCancelled: break } @@ -303,6 +322,11 @@ public enum CoreStoreErrorCode: Int { The transaction was cancelled by the user. */ case userCancelled + + /** + Attempted to perform a fetch but could not find any related persistent store. + */ + case persistentStoreNotFound } diff --git a/Sources/CoreStoreFetchedResultsController.swift b/Sources/CoreStoreFetchedResultsController.swift index f8e6280..5cad260 100644 --- a/Sources/CoreStoreFetchedResultsController.swift +++ b/Sources/CoreStoreFetchedResultsController.swift @@ -58,7 +58,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll self.reapplyAffectedStores = { fetchRequest, context in - return from.applyAffectedStoresForFetchedRequest(fetchRequest, context: context) + return try rom.applyAffectedStoresForFetchedRequest(fetchRequest, context: context) } super.init( @@ -71,14 +71,8 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll @nonobjc internal func performFetchFromSpecifiedStores() throws { - - if !self.reapplyAffectedStores(self.fetchRequest, self.managedObjectContext) { - - CoreStore.log( - .warning, - message: "Attempted to perform a fetch on an \(cs_typeName(self)) but could not find any persistent store for the entity \(cs_typeName(self.fetchRequest.entityName))" - ) - } + + try self.reapplyAffectedStores(self.fetchRequest, self.managedObjectContext) try self.performFetch() } @@ -97,5 +91,5 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll // MARK: Private @nonobjc - private let reapplyAffectedStores: (_ fetchRequest: NSFetchRequest, _ context: NSManagedObjectContext) -> Bool + private let reapplyAffectedStores: (_ fetchRequest: NSFetchRequest, _ context: NSManagedObjectContext) throws -> Bool } diff --git a/Sources/DataStack+Observing.swift b/Sources/DataStack+Observing.swift index 0e469ba..0bffe76 100644 --- a/Sources/DataStack+Observing.swift +++ b/Sources/DataStack+Observing.swift @@ -152,7 +152,7 @@ public extension DataStack { ``` dataStack.monitorList( - { (monitor) in + createAsynchronously: { (monitor) in self.monitor = monitor }, From() @@ -162,7 +162,6 @@ public extension DataStack { ``` - parameter createAsynchronously: the closure that receives the created `ListMonitor` instance - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - - returns: a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` */ public func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ clauseChain: B) { @@ -288,7 +287,7 @@ public extension DataStack { Asynchronously creates a `ListMonitor` for a sectioned list of `DynamicObject`s that satisfy the specified `SectionMonitorBuilderType` built from a chain of clauses. ``` dataStack.monitorSectionedList( - { (monitor) in + createAsynchronously: { (monitor) in self.monitor = monitor }, From() @@ -297,8 +296,8 @@ public extension DataStack { .orderBy(.ascending(\.age)) ) ``` + - parameter createAsynchronously: the closure that receives the created `ListMonitor` instance - parameter clauseChain: a `SectionMonitorBuilderType` built from a chain of clauses - - returns: a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified `SectionMonitorBuilderType` */ public func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ clauseChain: B) { diff --git a/Sources/DataStack+Querying.swift b/Sources/DataStack+Querying.swift index ba1374c..1d07566 100644 --- a/Sources/DataStack+Querying.swift +++ b/Sources/DataStack+Querying.swift @@ -84,13 +84,13 @@ 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...) -> D? { + public func fetchOne(_ from: From, _ fetchClauses: FetchClause...) throws -> D? { CoreStore.assert( Thread.isMainThread, "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) - return self.mainContext.fetchOne(from, fetchClauses) + return try self.mainContext.fetchOne(from, fetchClauses) } /** @@ -100,13 +100,13 @@ 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]) -> D? { + public func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) throws -> D? { CoreStore.assert( Thread.isMainThread, "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) - return self.mainContext.fetchOne(from, fetchClauses) + return try self.mainContext.fetchOne(from, fetchClauses) } /** @@ -121,13 +121,13 @@ extension DataStack: FetchableSource, QueryableSource { - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - returns: the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType` */ - public func fetchOne(_ clauseChain: B) -> B.ObjectType? { + public func fetchOne(_ clauseChain: B) throws -> B.ObjectType? { CoreStore.assert( Thread.isMainThread, "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) - return self.mainContext.fetchOne(clauseChain) + return try self.mainContext.fetchOne(clauseChain) } /** @@ -137,13 +137,13 @@ 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...) -> [D]? { + public func fetchAll(_ from: From, _ fetchClauses: FetchClause...) throws -> [D] { CoreStore.assert( Thread.isMainThread, "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) - return self.mainContext.fetchAll(from, fetchClauses) + return try self.mainContext.fetchAll(from, fetchClauses) } /** @@ -153,13 +153,13 @@ 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]) -> [D]? { + public func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) throws -> [D] { CoreStore.assert( Thread.isMainThread, "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) - return self.mainContext.fetchAll(from, fetchClauses) + return try self.mainContext.fetchAll(from, fetchClauses) } /** @@ -174,13 +174,13 @@ extension DataStack: FetchableSource, QueryableSource { - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - returns: all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType` */ - public func fetchAll(_ clauseChain: B) -> [B.ObjectType]? { + public func fetchAll(_ clauseChain: B) throws -> [B.ObjectType] { CoreStore.assert( Thread.isMainThread, "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) - return self.mainContext.fetchAll(clauseChain) + return try self.mainContext.fetchAll(clauseChain) } /** @@ -190,13 +190,13 @@ 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...) throws -> Int { CoreStore.assert( Thread.isMainThread, "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) - return self.mainContext.fetchCount(from, fetchClauses) + return try self.mainContext.fetchCount(from, fetchClauses) } /** @@ -206,13 +206,13 @@ 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]) throws -> Int { CoreStore.assert( Thread.isMainThread, "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) - return self.mainContext.fetchCount(from, fetchClauses) + return try self.mainContext.fetchCount(from, fetchClauses) } /** @@ -227,13 +227,13 @@ extension DataStack: FetchableSource, QueryableSource { - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - returns: the number `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` */ - public func fetchCount(_ clauseChain: B) -> Int? { + public func fetchCount(_ clauseChain: B) throws -> Int { CoreStore.assert( Thread.isMainThread, "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) - return self.mainContext.fetchCount(clauseChain) + return try self.mainContext.fetchCount(clauseChain) } /** diff --git a/Sources/FetchableSource.swift b/Sources/FetchableSource.swift index 31f1d50..38bc57d 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...) -> D? + func fetchOne(_ from: From, _ fetchClauses: FetchClause...) throws -> D? /** 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]) -> D? + func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) throws -> D? /** Fetches the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType` built from a chain of clauses. @@ -96,7 +96,7 @@ public protocol FetchableSource: class { - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - returns: the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType` */ - func fetchOne(_ clauseChain: B) -> B.ObjectType? + func fetchOne(_ clauseChain: B) throws -> B.ObjectType? /** Fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -105,7 +105,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...) -> [D]? + func fetchAll(_ from: From, _ fetchClauses: FetchClause...) throws -> [D] /** Fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -114,7 +114,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]) -> [D]? + func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) throws -> [D] /** Fetches all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses. @@ -128,7 +128,7 @@ public protocol FetchableSource: class { - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - returns: all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType` */ - func fetchAll(_ clauseChain: B) -> [B.ObjectType]? + func fetchAll(_ clauseChain: B) throws -> [B.ObjectType] /** Fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -137,7 +137,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...) throws -> Int /** Fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -146,7 +146,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]) throws -> Int /** Fetches the number of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses. @@ -160,7 +160,7 @@ public protocol FetchableSource: class { - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - returns: the number `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` */ - func fetchCount(_ clauseChain: B) -> Int? + func fetchCount(_ clauseChain: B) throws -> Int /** Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. diff --git a/Sources/From.swift b/Sources/From.swift index 65de91d..13b2e9e 100644 --- a/Sources/From.swift +++ b/Sources/From.swift @@ -139,29 +139,40 @@ 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) throws { fetchRequest.entity = context.parentStack!.entityDescription(for: EntityIdentifier(self.entityClass))! guard applyAffectedStores else { - return true + return } - if self.applyAffectedStoresForFetchedRequest(fetchRequest, context: context) { - - return true + do { + + try self.applyAffectedStoresForFetchedRequest(fetchRequest, context: context) + } + catch let error as CoreStoreError { + + CoreStore.log( + error, + "Attempted to perform a fetch but could not find any persistent store for the entity \(cs_typeName(fetchRequest.entityName))" + ) + throw error + } + catch { + + throw error } - CoreStore.log( - .warning, - message: "Attempted to perform a fetch but could not find any persistent store for the entity \(cs_typeName(fetchRequest.entityName))" - ) - return false } - internal func applyAffectedStoresForFetchedRequest(_ fetchRequest: NSFetchRequest, context: NSManagedObjectContext) -> Bool { + internal func applyAffectedStoresForFetchedRequest(_ fetchRequest: NSFetchRequest, context: NSManagedObjectContext) throws { let stores = self.findPersistentStores(context) fetchRequest.affectedStores = stores - return stores?.isEmpty == false + if stores?.isEmpty == false { + + return + } + throw CoreStoreError.persistentStoreNotFound(entity: self.entityClass) } diff --git a/Sources/ListMonitor.swift b/Sources/ListMonitor.swift index b8da0b1..6d9c3d1 100644 --- a/Sources/ListMonitor.swift +++ b/Sources/ListMonitor.swift @@ -136,7 +136,7 @@ public final class ListMonitor: Hashable { */ public subscript(safeSectionIndex sectionIndex: Int, safeItemIndex itemIndex: Int) -> ObjectType? { - guard let section = self.sectionInfoAtIndex(safeSectionIndex: sectionIndex) else { + guard let section = self.sectionInfo(safelyAt: sectionIndex) else { return nil } @@ -202,9 +202,9 @@ public final class ListMonitor: Hashable { - parameter section: the section index. Using an index outside the valid range will return `false`. - returns: `true` if at least one object in the specified section exists, `false` otherwise */ - public func hasObjectsInSection(_ section: Int) -> Bool { + public func hasObjects(in section: Int) -> Bool { - return self.numberOfObjectsInSection(safeSectionIndex: section)! > 0 + return self.numberOfObjects(safelyIn: section)! > 0 } /** @@ -241,9 +241,9 @@ public final class ListMonitor: Hashable { - parameter section: the section index. Using an index outside the valid range will raise an exception. - returns: the number of objects in the specified section */ - public func numberOfObjectsInSection(_ section: Int) -> Int { + public func numberOfObjects(in section: Int) -> Int { - return self.sectionInfoAtIndex(section).numberOfObjects + return self.sectionInfo(at: section).numberOfObjects } /** @@ -252,9 +252,9 @@ public final class ListMonitor: Hashable { - parameter section: the section index. Using an index outside the valid range will return `nil`. - returns: the number of objects in the specified section */ - public func numberOfObjectsInSection(safeSectionIndex section: Int) -> Int? { + public func numberOfObjects(safelyIn section: Int) -> Int? { - return self.sectionInfoAtIndex(safeSectionIndex: section)?.numberOfObjects + return self.sectionInfo(safelyAt: section)?.numberOfObjects } /** @@ -263,7 +263,7 @@ public final class ListMonitor: Hashable { - parameter section: the section index. Using an index outside the valid range will raise an exception. - returns: the `NSFetchedResultsSectionInfo` for the specified section */ - public func sectionInfoAtIndex(_ section: Int) -> NSFetchedResultsSectionInfo { + public func sectionInfo(at section: Int) -> NSFetchedResultsSectionInfo { CoreStore.assert( !self.isPendingRefetch || Thread.isMainThread, @@ -278,7 +278,7 @@ public final class ListMonitor: Hashable { - parameter section: the section index. Using an index outside the valid range will return `nil`. - returns: the `NSFetchedResultsSectionInfo` for the specified section, or `nil` if the section index is out of bounds. */ - public func sectionInfoAtIndex(safeSectionIndex section: Int) -> NSFetchedResultsSectionInfo? { + public func sectionInfo(safelyAt section: Int) -> NSFetchedResultsSectionInfo? { CoreStore.assert( !self.isPendingRefetch || Thread.isMainThread, @@ -312,17 +312,17 @@ public final class ListMonitor: Hashable { /** Returns the target section for a specified "Section Index" title and index. - - parameter title: the title of the Section Index - - parameter index: the index of the Section Index + - parameter sectionIndexTitle: the title of the Section Index + - parameter sectionIndex: the index of the Section Index - returns: the target section for the specified "Section Index" title and index. */ - public func targetSectionForSectionIndex(title: String, index: Int) -> Int { + public func targetSection(forSectionIndexTitle sectionIndexTitle: String, at sectionIndex: Int) -> Int { CoreStore.assert( !self.isPendingRefetch || Thread.isMainThread, "Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress." ) - return self.fetchedResultsController.section(forSectionIndexTitle: title, at: index) + return self.fetchedResultsController.section(forSectionIndexTitle: sectionIndexTitle, at: sectionIndex) } /** @@ -345,7 +345,7 @@ public final class ListMonitor: Hashable { - parameter object: the `DynamicObject` to search the index of - returns: the index of the `DynamicObject` if it exists in the `ListMonitor`'s fetched objects, or `nil` if not found. */ - public func indexOf(_ object: ObjectType) -> Int? { + public func index(of object: ObjectType) -> Int? { CoreStore.assert( !self.isPendingRefetch || Thread.isMainThread, @@ -364,7 +364,7 @@ public final class ListMonitor: Hashable { - parameter object: the `DynamicObject` to search the index of - returns: the `IndexPath` of the `DynamicObject` if it exists in the `ListMonitor`'s fetched objects, or `nil` if not found. */ - public func indexPathOf(_ object: ObjectType) -> IndexPath? { + public func indexPath(of object: ObjectType) -> IndexPath? { CoreStore.assert( !self.isPendingRefetch || Thread.isMainThread, @@ -1164,6 +1164,57 @@ public final class ListMonitor: Hashable { try! self.fetchedResultsController.performFetchFromSpecifiedStores() } } + + + // MARK: Deprecated + + @available(*, deprecated, renamed: "hasObjects(in:)") + public func hasObjectsInSection(_ section: Int) -> Bool { + + return self.hasObjects(in: section) + } + + @available(*, deprecated, renamed: "numberOfObjects(in:)") + public func numberOfObjectsInSection(_ section: Int) -> Int { + + return self.numberOfObjects(in: section) + } + + @available(*, deprecated, renamed: "numberOfObjects(safelyIn:)") + public func numberOfObjectsInSection(safeSectionIndex section: Int) -> Int? { + + return self.numberOfObjects(safelyIn: section) + } + + @available(*, deprecated, renamed: "sectionInfo(at:)") + public func sectionInfoAtIndex(_ section: Int) -> NSFetchedResultsSectionInfo { + + return self.sectionInfo(at: section) + } + + @available(*, deprecated, renamed: "sectionInfo(safelyAt:)") + public func sectionInfoAtIndex(safeSectionIndex section: Int) -> NSFetchedResultsSectionInfo? { + + return self.sectionInfo(safelyAt: section) + } + + @available(*, deprecated, renamed: "targetSection(forSectionIndexTitle:at:)") + public func targetSectionForSectionIndex(title: String, index: Int) -> Int { + + return self.targetSection(forSectionIndexTitle: title, at: index) + } + + @available(*, deprecated, renamed: "index(of:)") + public func indexOf(_ object: ObjectType) -> Int? { + + return self.index(of: object) + } + + @available(*, deprecated, renamed: "indexPath(of:)") + public func indexPathOf(_ object: ObjectType) -> IndexPath? { + + return self.indexPath(of: object) + } } @@ -1192,9 +1243,9 @@ extension ListMonitor where ListMonitor.ObjectType: NSManagedObject { - parameter section: the section index. Using an index outside the valid range will raise an exception. - returns: all objects in the specified section */ - public func objectsInSection(_ section: Int) -> [ObjectType] { + public func objects(in section: Int) -> [ObjectType] { - return (self.sectionInfoAtIndex(section).objects as! [ObjectType]?) ?? [] + return (self.sectionInfo(at: section).objects as! [ObjectType]?) ?? [] } /** @@ -1203,9 +1254,24 @@ extension ListMonitor where ListMonitor.ObjectType: NSManagedObject { - parameter section: the section index. Using an index outside the valid range will return `nil`. - returns: all objects in the specified section */ - public func objectsInSection(safeSectionIndex section: Int) -> [ObjectType]? { + public func objects(safelyIn section: Int) -> [ObjectType]? { - return self.sectionInfoAtIndex(safeSectionIndex: section)?.objects as! [ObjectType]? + return self.sectionInfo(safelyAt: section)?.objects as! [ObjectType]? + } + + + // MARK: Deprecated + + @available(*, deprecated, renamed: "objects(in:)") + public func objectsInSection(_ section: Int) -> [ObjectType] { + + return self.objects(in: section) + } + + @available(*, deprecated, renamed: "objects(safelyIn:)") + public func objectsInSection(safeSectionIndex section: Int) -> [ObjectType]? { + + return self.objects(safelyIn: section) } } @@ -1236,9 +1302,9 @@ extension ListMonitor where ListMonitor.ObjectType: CoreStoreObject { - parameter section: the section index. Using an index outside the valid range will raise an exception. - returns: all objects in the specified section */ - public func objectsInSection(_ section: Int) -> [ObjectType] { + public func objects(in section: Int) -> [ObjectType] { - return (self.sectionInfoAtIndex(section).objects ?? []) + return (self.sectionInfo(at: section).objects ?? []) .map({ ObjectType.cs_fromRaw(object: $0 as! NSManagedObject) }) } @@ -1248,11 +1314,26 @@ extension ListMonitor where ListMonitor.ObjectType: CoreStoreObject { - parameter section: the section index. Using an index outside the valid range will return `nil`. - returns: all objects in the specified section */ - public func objectsInSection(safeSectionIndex section: Int) -> [ObjectType]? { + public func objects(safelyIn section: Int) -> [ObjectType]? { - return (self.sectionInfoAtIndex(safeSectionIndex: section)?.objects)? + return (self.sectionInfo(safelyAt: section)?.objects)? .map({ ObjectType.cs_fromRaw(object: $0 as! NSManagedObject) }) } + + + // MARK: Deprecated + + @available(*, deprecated, renamed: "objects(in:)") + public func objectsInSection(_ section: Int) -> [ObjectType] { + + return self.objects(in: section) + } + + @available(*, deprecated, renamed: "objects(safelyIn:)") + public func objectsInSection(safeSectionIndex section: Int) -> [ObjectType]? { + + return self.objects(safelyIn: section) + } } diff --git a/Sources/NSManagedObjectContext+ObjectiveC.swift b/Sources/NSManagedObjectContext+ObjectiveC.swift index 4b1b259..a2482b6 100644 --- a/Sources/NSManagedObjectContext+ObjectiveC.swift +++ b/Sources/NSManagedObjectContext+ObjectiveC.swift @@ -34,85 +34,65 @@ internal extension NSManagedObjectContext { // MARK: Internal @nonobjc - internal func fetchOne(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) -> NSManagedObject? { + internal func fetchOne(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) throws -> NSManagedObject? { let fetchRequest = CoreStoreFetchRequest() - let storeFound = from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self) + try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 1 fetchRequest.resultType = .managedObjectResultType fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) } - - guard storeFound else { - - return nil - } - return self.fetchOne(fetchRequest.dynamicCast()) + + return try self.fetchOne(fetchRequest.dynamicCast()) } @nonobjc - internal func fetchAll(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) -> [T]? { + internal func fetchAll(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) throws -> [T] { let fetchRequest = CoreStoreFetchRequest() - let storeFound = from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self) + try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 0 fetchRequest.resultType = .managedObjectResultType fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) } - - guard storeFound else { - - return nil - } - return self.fetchAll(fetchRequest.dynamicCast()) + + return try self.fetchAll(fetchRequest.dynamicCast()) } @nonobjc - internal func fetchCount(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) -> Int? { + internal func fetchCount(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) throws -> Int { let fetchRequest = CoreStoreFetchRequest() - let storeFound = from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self) + try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self) fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) } - - guard storeFound else { - - return nil - } - return self.fetchCount(fetchRequest.dynamicCast()) + + return try self.fetchCount(fetchRequest.dynamicCast()) } @nonobjc - internal func fetchObjectID(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) -> NSManagedObjectID? { + internal func fetchObjectID(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) throws -> NSManagedObjectID? { let fetchRequest = CoreStoreFetchRequest() - let storeFound = from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self) + try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 1 fetchRequest.resultType = .managedObjectIDResultType fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) } - - guard storeFound else { - - return nil - } - return self.fetchObjectID(fetchRequest.dynamicCast()) + + return try self.fetchObjectID(fetchRequest.dynamicCast()) } @nonobjc - internal func fetchObjectIDs(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) -> [NSManagedObjectID]? { + internal func fetchObjectIDs(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) throws -> [NSManagedObjectID] { let fetchRequest = CoreStoreFetchRequest() - let storeFound = from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self) + try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 0 fetchRequest.resultType = .managedObjectIDResultType fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) } - - guard storeFound else { - - return nil - } - return self.fetchObjectIDs(fetchRequest.dynamicCast()) + + return try self.fetchObjectIDs(fetchRequest.dynamicCast()) } @nonobjc diff --git a/Sources/NSManagedObjectContext+Querying.swift b/Sources/NSManagedObjectContext+Querying.swift index 6625833..57b747e 100644 --- a/Sources/NSManagedObjectContext+Querying.swift +++ b/Sources/NSManagedObjectContext+Querying.swift @@ -101,88 +101,76 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { } @nonobjc - public func fetchOne(_ from: From, _ fetchClauses: FetchClause...) -> D? { + public func fetchOne(_ from: From, _ fetchClauses: FetchClause...) throws -> D? { - return self.fetchOne(from, fetchClauses) + return try self.fetchOne(from, fetchClauses) } @nonobjc - public func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) -> D? { + public func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) throws -> D? { let fetchRequest = CoreStoreFetchRequest() - let storeFound = from.applyToFetchRequest(fetchRequest, context: self) + try from.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 1 fetchRequest.resultType = .managedObjectResultType fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) } - - guard storeFound else { - - return nil - } - return self.fetchOne(fetchRequest.dynamicCast()).flatMap(from.entityClass.cs_fromRaw) + + return try self.fetchOne(fetchRequest.dynamicCast()).flatMap(from.entityClass.cs_fromRaw) } @nonobjc - public func fetchOne(_ clauseChain: B) -> B.ObjectType? { + public func fetchOne(_ clauseChain: B) throws -> B.ObjectType? { - return self.fetchOne(clauseChain.from, clauseChain.fetchClauses) + return try self.fetchOne(clauseChain.from, clauseChain.fetchClauses) } @nonobjc - public func fetchAll(_ from: From, _ fetchClauses: FetchClause...) -> [D]? { + public func fetchAll(_ from: From, _ fetchClauses: FetchClause...) throws -> [D] { - return self.fetchAll(from, fetchClauses) + return try self.fetchAll(from, fetchClauses) } @nonobjc - public func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) -> [D]? { + public func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) throws -> [D] { let fetchRequest = CoreStoreFetchRequest() - let storeFound = from.applyToFetchRequest(fetchRequest, context: self) + try from.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 0 fetchRequest.resultType = .managedObjectResultType fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) } - - guard storeFound else { - - return nil - } + let entityClass = from.entityClass - return self.fetchAll(fetchRequest.dynamicCast())?.map(entityClass.cs_fromRaw) + return try self.fetchAll(fetchRequest.dynamicCast())?.map(entityClass.cs_fromRaw) } @nonobjc - public func fetchAll(_ clauseChain: B) -> [B.ObjectType]? { + public func fetchAll(_ clauseChain: B) throw -> [B.ObjectType] { - return self.fetchAll(clauseChain.from, clauseChain.fetchClauses) + return try self.fetchAll(clauseChain.from, clauseChain.fetchClauses) } @nonobjc - public func fetchCount(_ from: From, _ fetchClauses: FetchClause...) -> Int? { + public func fetchCount(_ from: From, _ fetchClauses: FetchClause...) throws -> Int { - return self.fetchCount(from, fetchClauses) + return try self.fetchCount(from, fetchClauses) } @nonobjc - public func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) -> Int? { + public func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) throws -> Int { let fetchRequest = CoreStoreFetchRequest() - let storeFound = from.applyToFetchRequest(fetchRequest, context: self) + try from.applyToFetchRequest(fetchRequest, context: self) fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) } - - guard storeFound else { - - return nil - } - return self.fetchCount(fetchRequest.dynamicCast()) + + return try self.fetchCount(fetchRequest.dynamicCast()) } @nonobjc - public func fetchCount(_ clauseChain: B) -> Int? { + public func fetchCount(_ clauseChain: B) throws -> Int { - return self.fetchCount(clauseChain.from, clauseChain.fetchClauses) + return try self.fetchCount(clauseChain.from, clauseChain.fetchClauses) } @nonobjc @@ -207,8 +195,7 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { } return self.fetchObjectID(fetchRequest.dynamicCast()) } - - // TODO: docs + @nonobjc public func fetchObjectID(_ clauseChain: B) -> NSManagedObjectID? { @@ -225,7 +212,7 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { public func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? { let fetchRequest = CoreStoreFetchRequest() - let storeFound = from.applyToFetchRequest(fetchRequest, context: self) + try from.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 0 fetchRequest.resultType = .managedObjectIDResultType @@ -237,8 +224,7 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { } return self.fetchObjectIDs(fetchRequest.dynamicCast()) } - - // TODO: docs + @nonobjc public func fetchObjectIDs(_ clauseChain: B) -> [NSManagedObjectID]? { @@ -383,7 +369,7 @@ internal extension NSManagedObjectContext { // MARK: Fetching @nonobjc - internal func fetchOne(_ fetchRequest: NSFetchRequest) -> D? { + internal func fetchOne(_ fetchRequest: NSFetchRequest) throws -> D? { var fetchResults: [D]? var fetchError: Error? @@ -399,18 +385,19 @@ internal extension NSManagedObjectContext { } } if fetchResults == nil { - + + let coreStoreError = CoreStoreError(fetchError) CoreStore.log( - CoreStoreError(fetchError), + coreStoreError, "Failed executing fetch request." ) - return nil + throw coreStoreError } return fetchResults?.first } @nonobjc - internal func fetchAll(_ fetchRequest: NSFetchRequest) -> [D]? { + internal func fetchAll(_ fetchRequest: NSFetchRequest) throws -> [D] { var fetchResults: [D]? var fetchError: Error? @@ -426,18 +413,19 @@ internal extension NSManagedObjectContext { } } if fetchResults == nil { - + + let coreStoreError = CoreStoreError(fetchError) CoreStore.log( - CoreStoreError(fetchError), + coreStoreError, "Failed executing fetch request." ) - return nil + throw coreStoreError } return fetchResults } @nonobjc - internal func fetchCount(_ fetchRequest: NSFetchRequest) -> Int? { + internal func fetchCount(_ fetchRequest: NSFetchRequest) throws -> Int { var count = 0 var countError: Error? @@ -453,12 +441,13 @@ internal extension NSManagedObjectContext { } } if count == NSNotFound { - + + let coreStoreError = CoreStoreError(fetchError) CoreStore.log( - CoreStoreError(countError), + coreStoreError, "Failed executing count request." ) - return nil + throw coreStoreError } return count } diff --git a/Sources/UnsafeDataTransaction+Observing.swift b/Sources/UnsafeDataTransaction+Observing.swift index 7287ed6..3ca12ac 100644 --- a/Sources/UnsafeDataTransaction+Observing.swift +++ b/Sources/UnsafeDataTransaction+Observing.swift @@ -142,8 +142,23 @@ public extension UnsafeDataTransaction { createAsynchronously: createAsynchronously ) } - - // TODO: docs + + /** + Asynchronously creates a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses. Since `NSFetchedResultsController` greedily locks the persistent store on initial fetch, you may prefer this method instead of the synchronous counterpart to avoid deadlocks while background updates/saves are being executed. + + ``` + dataStack.monitorList( + createAsynchronously: { (monitor) in + self.monitor = monitor + }, + From() + .where(\.age > 18) + .orderBy(.ascending(\.age)) + ) + ``` + - parameter createAsynchronously: the closure that receives the created `ListMonitor` instance + - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses + */ public func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ clauseChain: B) { self.monitorList( @@ -267,8 +282,8 @@ public extension UnsafeDataTransaction { .orderBy(.ascending(\.age)) ) ``` + - parameter createAsynchronously: the closure that receives the created `ListMonitor` instance - parameter clauseChain: a `SectionMonitorBuilderType` built from a chain of clauses - - returns: a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified `SectionMonitorBuilderType` */ public func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ clauseChain: B) { diff --git a/Sources/Where.swift b/Sources/Where.swift index ae98cc5..5e2da49 100644 --- a/Sources/Where.swift +++ b/Sources/Where.swift @@ -541,7 +541,7 @@ public extension Sequence where Iterator.Element: WhereClauseType { public extension Where { - @available(*, deprecated: 4.0, renamed: "&&?") + @available(*, deprecated, renamed: "&&?") public static func && (left: Where, right: Where?) -> Where { if let right = right { @@ -551,7 +551,7 @@ public extension Where { return left } - @available(*, deprecated: 4.0, renamed: "&&?") + @available(*, deprecated, renamed: "&&?") public static func && (left: Where?, right: Where) -> Where { if let left = left { @@ -561,7 +561,7 @@ public extension Where { return right } - @available(*, deprecated: 4.0, renamed: "||?") + @available(*, deprecated, renamed: "||?") public static func || (left: Where, right: Where?) -> Where { if let right = right { @@ -571,7 +571,7 @@ public extension Where { return left } - @available(*, deprecated: 4.0, renamed: "||?") + @available(*, deprecated, renamed: "||?") public static func || (left: Where?, right: Where) -> Where { if let left = left { From 682472c1bdc8f5219730d5f75d347fb6ec3fe3ab Mon Sep 17 00:00:00 2001 From: John Estropia Date: Tue, 15 Jan 2019 20:40:15 +0900 Subject: [PATCH 2/4] fetches, queries, and deletes are now throwable methods --- CoreStoreDemo/CoreStoreDemo/AppDelegate.swift | 1 - ...etchingAndQueryingDemoViewController.swift | 42 +- .../ListObserverDemoViewController.swift | 8 +- .../ObjectObserverDemoViewController.swift | 4 +- .../CustomLoggerViewController.swift | 2 +- .../MigrationsDemoViewController.swift | 8 +- .../StackSetupDemoViewController.swift | 8 +- .../TransactionsDemoViewController.swift | 4 +- CoreStoreTests/BaseTests/BaseTestCase.swift | 9 +- CoreStoreTests/DynamicModelTests.swift | 20 +- CoreStoreTests/FetchTests.swift | 1206 ++++++++--------- CoreStoreTests/FromTests.swift | 99 +- CoreStoreTests/GroupByTests.swift | 2 +- CoreStoreTests/ImportTests.swift | 116 +- CoreStoreTests/ListObserverTests.swift | 16 +- CoreStoreTests/ObjectObserverTests.swift | 4 +- CoreStoreTests/QueryTests.swift | 244 ++-- CoreStoreTests/TransactionTests.swift | 315 +++-- Sources/BaseDataTransaction+Importing.swift | 5 +- Sources/BaseDataTransaction+Querying.swift | 60 +- Sources/CSBaseDataTransaction+Querying.swift | 20 +- Sources/CSDataStack+Querying.swift | 23 +- ...reStore+CustomDebugStringConvertible.swift | 4 + Sources/CoreStore+Querying.swift | 48 +- .../CoreStoreFetchedResultsController.swift | 6 +- Sources/DataStack+Querying.swift | 48 +- Sources/FetchableSource.swift | 12 +- .../NSManagedObjectContext+ObjectiveC.swift | 36 +- Sources/NSManagedObjectContext+Querying.swift | 209 ++- Sources/QueryableSource.swift | 12 +- 30 files changed, 1239 insertions(+), 1352 deletions(-) diff --git a/CoreStoreDemo/CoreStoreDemo/AppDelegate.swift b/CoreStoreDemo/CoreStoreDemo/AppDelegate.swift index e3be77d..71d51e2 100644 --- a/CoreStoreDemo/CoreStoreDemo/AppDelegate.swift +++ b/CoreStoreDemo/CoreStoreDemo/AppDelegate.swift @@ -20,7 +20,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]? = nil) -> Bool { - application.statusBarStyle = .lightContent return true } } diff --git a/CoreStoreDemo/CoreStoreDemo/Fetching and Querying Demo/FetchingAndQueryingDemoViewController.swift b/CoreStoreDemo/CoreStoreDemo/Fetching and Querying Demo/FetchingAndQueryingDemoViewController.swift index 9a62511..9ff315d 100644 --- a/CoreStoreDemo/CoreStoreDemo/Fetching and Querying Demo/FetchingAndQueryingDemoViewController.swift +++ b/CoreStoreDemo/CoreStoreDemo/Fetching and Querying Demo/FetchingAndQueryingDemoViewController.swift @@ -25,7 +25,7 @@ private struct Static { _ = try? dataStack.perform( synchronous: { (transaction) in - transaction.deleteAll(From()) + try transaction.deleteAll(From()) for name in NSTimeZone.knownTimeZoneNames { @@ -164,17 +164,17 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo title: "All Time Zones", fetch: { () -> [TimeZone] in - return Static.timeZonesStack.fetchAll( + return try! Static.timeZonesStack.fetchAll( From() .orderBy(.ascending(\.name)) - )! + ) } ), ( title: "Time Zones in Asia", fetch: { () -> [TimeZone] in - return Static.timeZonesStack.fetchAll( + return try! Static.timeZonesStack.fetchAll( From() .where( format: "%K BEGINSWITH[c] %@", @@ -182,14 +182,14 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo "Asia" ) .orderBy(.ascending(\.secondsFromGMT)) - )! + ) } ), ( title: "Time Zones in America and Europe", fetch: { () -> [TimeZone] in - return Static.timeZonesStack.fetchAll( + return try! Static.timeZonesStack.fetchAll( From() .where( format: "%K BEGINSWITH[c] %@ OR %K BEGINSWITH[c] %@", @@ -199,14 +199,14 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo "Europe" ) .orderBy(.ascending(\.secondsFromGMT)) - )! + ) } ), ( title: "All Time Zones Except America", fetch: { () -> [TimeZone] in - return Static.timeZonesStack.fetchAll( + return try! Static.timeZonesStack.fetchAll( From() .where( format: "%K BEGINSWITH[c] %@", @@ -214,18 +214,18 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo "America" ) .orderBy(.ascending(\.secondsFromGMT)) - )! + ) } ), ( title: "Time Zones with Summer Time", fetch: { () -> [TimeZone] in - return Static.timeZonesStack.fetchAll( + return try! Static.timeZonesStack.fetchAll( From() .where(\.hasDaylightSavingTime == true) .orderBy(.ascending(\.name)) - )! + ) } ) ] @@ -235,28 +235,28 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo title: "Number of Time Zones", query: { () -> Any in - return Static.timeZonesStack.queryValue( + return try! Static.timeZonesStack.queryValue( From() .select(NSNumber.self, .count(\.name)) - )! as Any + )! } ), ( title: "Abbreviation For Tokyo's Time Zone", query: { () -> Any in - return Static.timeZonesStack.queryValue( + return try! Static.timeZonesStack.queryValue( From() .select(String.self, .attribute(\.abbreviation)) .where(format: "%K ENDSWITH[c] %@", #keyPath(TimeZone.name), "Tokyo") - )! as Any + )! } ), ( title: "All Abbreviations", query: { () -> Any in - return Static.timeZonesStack.queryAttributes( + return try! Static.timeZonesStack.queryAttributes( From() .select( NSDictionary.self, @@ -264,14 +264,14 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo .attribute(\.abbreviation) ) .orderBy(.ascending(\.name)) - )! + ) } ), ( title: "Number of Countries per Time Zone", query: { () -> Any in - return Static.timeZonesStack.queryAttributes( + return try! Static.timeZonesStack.queryAttributes( From() .select( NSDictionary.self, @@ -283,14 +283,14 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo .ascending(\.secondsFromGMT), .ascending(\.name) ) - )! + ) } ), ( title: "Number of Countries with Summer Time", query: { () -> Any in - return Static.timeZonesStack.queryAttributes( + return try! Static.timeZonesStack.queryAttributes( From() .select( NSDictionary.self, @@ -302,7 +302,7 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo .descending(\.hasDaylightSavingTime), .ascending(\.name) ) - )! + ) } ) ] diff --git a/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ListObserverDemoViewController.swift b/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ListObserverDemoViewController.swift index 2af3317..18e0b26 100644 --- a/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ListObserverDemoViewController.swift +++ b/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ListObserverDemoViewController.swift @@ -160,7 +160,7 @@ class ListObserverDemoViewController: UITableViewController, ListSectionObserver override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return ColorsDemo.palettes.numberOfObjectsInSection(section) + return ColorsDemo.palettes.numberOfObjects(in: section) } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { @@ -208,7 +208,7 @@ class ListObserverDemoViewController: UITableViewController, ListSectionObserver override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { - return ColorsDemo.palettes.sectionInfoAtIndex(section).name + return ColorsDemo.palettes.sectionInfo(at: section).name } @@ -288,7 +288,7 @@ class ListObserverDemoViewController: UITableViewController, ListSectionObserver ColorsDemo.stack.perform( asynchronous: { (transaction) in - transaction.deleteAll(From()) + try transaction.deleteAll(From()) }, completion: { _ in } ) @@ -316,7 +316,7 @@ class ListObserverDemoViewController: UITableViewController, ListSectionObserver ColorsDemo.stack.perform( asynchronous: { (transaction) in - for palette in (transaction.fetchAll(From()) ?? []) { + for palette in try transaction.fetchAll(From()) { palette.hue .= Palette.randomHue() palette.colorName .= nil diff --git a/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ObjectObserverDemoViewController.swift b/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ObjectObserverDemoViewController.swift index f76d107..c7c006c 100644 --- a/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ObjectObserverDemoViewController.swift +++ b/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ObjectObserverDemoViewController.swift @@ -50,7 +50,7 @@ class ObjectObserverDemoViewController: UIViewController, ObjectObserver { required init?(coder aDecoder: NSCoder) { - if let palette = ColorsDemo.stack.fetchOne(From().orderBy(.ascending(\.hue))) { + if let palette = try! ColorsDemo.stack.fetchOne(From().orderBy(.ascending(\.hue))) { self.monitor = ColorsDemo.stack.monitorObject(palette) } @@ -64,7 +64,7 @@ class ObjectObserverDemoViewController: UIViewController, ObjectObserver { } ) - let palette = ColorsDemo.stack.fetchOne(From().orderBy(.ascending(\.hue)))! + let palette = try! ColorsDemo.stack.fetchOne(From().orderBy(.ascending(\.hue)))! self.monitor = ColorsDemo.stack.monitorObject(palette) } diff --git a/CoreStoreDemo/CoreStoreDemo/Loggers Demo/CustomLoggerViewController.swift b/CoreStoreDemo/CoreStoreDemo/Loggers Demo/CustomLoggerViewController.swift index c92bbaf..742b5e9 100644 --- a/CoreStoreDemo/CoreStoreDemo/Loggers Demo/CustomLoggerViewController.swift +++ b/CoreStoreDemo/CoreStoreDemo/Loggers Demo/CustomLoggerViewController.swift @@ -116,7 +116,7 @@ class CustomLoggerViewController: UIViewController, CoreStoreLogger { case 2?: DispatchQueue.global(qos: .background).async { - _ = self.dataStack.fetchOne(From()) + _ = try! self.dataStack.fetchOne(From()) } default: diff --git a/CoreStoreDemo/CoreStoreDemo/MIgrations Demo/MigrationsDemoViewController.swift b/CoreStoreDemo/CoreStoreDemo/MIgrations Demo/MigrationsDemoViewController.swift index 7443e71..088225d 100644 --- a/CoreStoreDemo/CoreStoreDemo/MIgrations Demo/MigrationsDemoViewController.swift +++ b/CoreStoreDemo/CoreStoreDemo/MIgrations Demo/MigrationsDemoViewController.swift @@ -79,7 +79,7 @@ class MigrationsDemoViewController: UIViewController, ListObserver, UITableViewD func listMonitorDidChange(_ monitor: ListMonitor) { if self.lastSelectedIndexPath == nil, - let numberOfObjectsInSection = self.listMonitor?.numberOfObjectsInSection(0), + let numberOfObjectsInSection = self.listMonitor?.numberOfObjects(in: 0), numberOfObjectsInSection > 0 { self.tableView?.reloadData() @@ -100,7 +100,7 @@ class MigrationsDemoViewController: UIViewController, ListObserver, UITableViewD @objc dynamic func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return self.listMonitor?.numberOfObjectsInSection(0) ?? 0 + return self.listMonitor?.numberOfObjects(in: 0) ?? 0 } @objc dynamic func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { @@ -286,7 +286,7 @@ class MigrationsDemoViewController: UIViewController, ListObserver, UITableViewD self.set(dataStack: dataStack, model: model, scrollToSelection: true) - let count = dataStack.queryValue( + let count = try! dataStack.queryValue( From(model.entityType) .select(Int.self, .count(#keyPath(OrganismV1.dna))))! if count > 0 { @@ -378,7 +378,7 @@ class MigrationsDemoViewController: UIViewController, ListObserver, UITableViewD if self.lastSelectedIndexPath == nil { - if listMonitor.numberOfObjectsInSection(0) > 0 { + if listMonitor.numberOfObjects(in: 0) > 0 { self.setSelectedIndexPath(IndexPath(row: 0, section: 0), scrollToSelection: true) } diff --git a/CoreStoreDemo/CoreStoreDemo/Stack Setup Demo/StackSetupDemoViewController.swift b/CoreStoreDemo/CoreStoreDemo/Stack Setup Demo/StackSetupDemoViewController.swift index 1487f31..9ecfd58 100644 --- a/CoreStoreDemo/CoreStoreDemo/Stack Setup Demo/StackSetupDemoViewController.swift +++ b/CoreStoreDemo/CoreStoreDemo/Stack Setup Demo/StackSetupDemoViewController.swift @@ -36,7 +36,7 @@ private struct Static { _ = try? dataStack.perform( synchronous: { (transaction) in - transaction.deleteAll(From()) + try transaction.deleteAll(From()) let account1 = transaction.create(Into(maleConfiguration)) account1.accountType = "Facebook" @@ -74,7 +74,7 @@ private struct Static { _ = try? dataStack.perform( synchronous: { (transaction) in - transaction.deleteAll(From()) + try transaction.deleteAll(From()) let account1 = transaction.create(Into(maleConfiguration)) account1.accountType = "Twitter" @@ -99,8 +99,8 @@ private struct Static { class StackSetupDemoViewController: UITableViewController { let accounts = [ - Static.facebookStack.fetchAll(From(UserAccount.self)) ?? [], - Static.twitterStack.fetchAll(From(UserAccount.self)) ?? [] + try! Static.facebookStack.fetchAll(From()), + try! Static.twitterStack.fetchAll(From()) ] diff --git a/CoreStoreDemo/CoreStoreDemo/Transactions Demo/TransactionsDemoViewController.swift b/CoreStoreDemo/CoreStoreDemo/Transactions Demo/TransactionsDemoViewController.swift index b7c67fa..e665855 100644 --- a/CoreStoreDemo/CoreStoreDemo/Transactions Demo/TransactionsDemoViewController.swift +++ b/CoreStoreDemo/CoreStoreDemo/Transactions Demo/TransactionsDemoViewController.swift @@ -26,7 +26,7 @@ private struct Static { ) ) - var place = CoreStore.fetchOne(From()) + var place = try! CoreStore.fetchOne(From()) if place == nil { _ = try? CoreStore.perform( @@ -36,7 +36,7 @@ private struct Static { place.setInitialValues() } ) - place = CoreStore.fetchOne(From()) + place = try! CoreStore.fetchOne(From()) } return CoreStore.monitorObject(place!) diff --git a/CoreStoreTests/BaseTests/BaseTestCase.swift b/CoreStoreTests/BaseTests/BaseTestCase.swift index d2e75b9..cebbb28 100644 --- a/CoreStoreTests/BaseTests/BaseTestCase.swift +++ b/CoreStoreTests/BaseTests/BaseTestCase.swift @@ -36,8 +36,7 @@ class BaseTestCase: XCTestCase { // MARK: Internal @nonobjc - @discardableResult - func prepareStack(configurations: [ModelConfiguration] = [nil], _ closure: (_ dataStack: DataStack) -> T) -> T { + func prepareStack(configurations: [ModelConfiguration] = [nil], _ closure: (_ dataStack: DataStack) throws -> Void) { let stack = DataStack( xcodeModelName: "Model", @@ -57,16 +56,16 @@ class BaseTestCase: XCTestCase { ) ) } + try closure(stack) } catch let error as NSError { XCTFail(error.coreStoreDumpString) } - return closure(stack) } @nonobjc - func expectLogger(_ expectations: [TestLogger.Expectation], closure: () -> T) -> T { + func expectLogger(_ expectations: [TestLogger.Expectation], closure: () throws -> T) rethrows -> T { CoreStore.logger = TestLogger(self.prepareLoggerExpectations(expectations)) defer { @@ -74,7 +73,7 @@ class BaseTestCase: XCTestCase { self.checkExpectationsImmediately() CoreStore.logger = TestLogger([:]) } - return closure() + return try closure() } @nonobjc diff --git a/CoreStoreTests/DynamicModelTests.swift b/CoreStoreTests/DynamicModelTests.swift index bdc877a..1cb66c9 100644 --- a/CoreStoreTests/DynamicModelTests.swift +++ b/CoreStoreTests/DynamicModelTests.swift @@ -248,51 +248,51 @@ class DynamicModelTests: BaseTestDataTestCase { let p1 = Where({ $0.species == "Sparrow" }) XCTAssertEqual(p1.predicate, NSPredicate(format: "%K == %@", "species", "Sparrow")) - let bird = transaction.fetchOne(From(), p1) + let bird = try transaction.fetchOne(From(), p1) XCTAssertNotNil(bird) XCTAssertEqual(bird!.species.value, "Sparrow") let p2 = Where({ $0.nickname == "Spot" }) XCTAssertEqual(p2.predicate, NSPredicate(format: "%K == %@", "nickname", "Spot")) - let dog = transaction.fetchOne(From().where(\.nickname == "Spot")) + let dog = try transaction.fetchOne(From().where(\.nickname == "Spot")) XCTAssertNotNil(dog) XCTAssertEqual(dog!.nickname.value, "Spot") XCTAssertEqual(dog!.species.value, "Dog") - let person = transaction.fetchOne(From()) + let person = try transaction.fetchOne(From()) XCTAssertNotNil(person) XCTAssertEqual(person!.pets.value.first, dog) let p3 = Where({ $0.age == 10 }) XCTAssertEqual(p3.predicate, NSPredicate(format: "%K == %d", "age", 10)) - _ = transaction.fetchAll( + _ = try transaction.fetchAll( From() .where(\Animal.species == "Dog" && \.age == 10) ) - _ = transaction.fetchAll( + _ = try transaction.fetchAll( From() .where(\.age == 10 && \Animal.species == "Dog") .orderBy(.ascending({ $0.species })) ) - _ = transaction.fetchAll( + _ = try transaction.fetchAll( From(), Where({ $0.age > 10 && $0.age <= 15 }) ) - _ = transaction.fetchAll( + _ = try transaction.fetchAll( From(), Where({ $0.species == "Dog" && $0.age == 10 }) ) - _ = transaction.fetchAll( + _ = try transaction.fetchAll( From(), Where({ $0.age == 10 && $0.species == "Dog" }) ) - _ = transaction.fetchAll( + _ = try transaction.fetchAll( From(), Where({ $0.age > 10 && $0.age <= 15 }) ) - _ = transaction.fetchAll( + _ = try transaction.fetchAll( From(), (\Dog.age > 10 && \Dog.age <= 15) ) diff --git a/CoreStoreTests/FetchTests.swift b/CoreStoreTests/FetchTests.swift index 5b81514..8d7f76e 100644 --- a/CoreStoreTests/FetchTests.swift +++ b/CoreStoreTests/FetchTests.swift @@ -45,7 +45,7 @@ final class FetchTests: BaseTestDataTestCase { let fetchClauses: [FetchClause] = [ OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = stack.fetchOne(from, fetchClauses)! + let object = try stack.fetchOne(from, fetchClauses)! do { let existing = stack.fetchExisting(object) @@ -148,7 +148,7 @@ final class FetchTests: BaseTestDataTestCase { let fetchClauses: [FetchClause] = [ OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let objects = stack.fetchAll(from, fetchClauses)! + let objects = try stack.fetchAll(from, fetchClauses) do { let existing = stack.fetchExisting(objects) @@ -288,11 +288,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = stack.fetchOne(from, fetchClauses) + let object = try stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testString, "nil:TestEntity1:2") - let objectID = stack.fetchObjectID(from, fetchClauses) + let objectID = try stack.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -302,11 +302,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] - let object = stack.fetchOne(from, fetchClauses) + let object = try stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testString, "nil:TestEntity1:3") - let objectID = stack.fetchObjectID(from, fetchClauses) + let objectID = try stack.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -316,10 +316,10 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = stack.fetchOne(from, fetchClauses) + let object = try stack.fetchOne(from, fetchClauses) XCTAssertNil(object) - let objectID = stack.fetchObjectID(from, fetchClauses) + let objectID = try stack.fetchObjectID(from, fetchClauses) XCTAssertNil(objectID) } } @@ -332,11 +332,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = stack.fetchOne(from, fetchClauses) + let object = try stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testString, "nil:TestEntity1:2") - let objectID = stack.fetchObjectID(from, fetchClauses) + let objectID = try stack.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -346,11 +346,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] - let object = stack.fetchOne(from, fetchClauses) + let object = try stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testString, "nil:TestEntity1:3") - let objectID = stack.fetchObjectID(from, fetchClauses) + let objectID = try stack.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -360,10 +360,10 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = stack.fetchOne(from, fetchClauses) + let object = try stack.fetchOne(from, fetchClauses) XCTAssertNil(object) - let objectID = stack.fetchObjectID(from, fetchClauses) + let objectID = try stack.fetchObjectID(from, fetchClauses) XCTAssertNil(objectID) } } @@ -376,17 +376,17 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = self.expectLogger([.logWarning]) { + let object = try? self.expectLogger([.logError]) { - stack.fetchOne(from, fetchClauses) + try stack.fetchOne(from, fetchClauses) } - XCTAssertNil(object) + XCTAssertNil(object as Any?) - let objectID = self.expectLogger([.logWarning]) { + let objectID = try? self.expectLogger([.logError]) { - stack.fetchObjectID(from, fetchClauses) + try stack.fetchObjectID(from, fetchClauses) } - XCTAssertNil(objectID) + XCTAssertNil(objectID as Any?) } do { @@ -394,17 +394,17 @@ final class FetchTests: BaseTestDataTestCase { Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] - let object = self.expectLogger([.logWarning]) { + let object = try? self.expectLogger([.logError]) { - stack.fetchOne(from, fetchClauses) + try stack.fetchOne(from, fetchClauses) } - XCTAssertNil(object) + XCTAssertNil(object as Any?) - let objectID = self.expectLogger([.logWarning]) { + let objectID = try? self.expectLogger([.logError]) { - stack.fetchObjectID(from, fetchClauses) + try stack.fetchObjectID(from, fetchClauses) } - XCTAssertNil(objectID) + XCTAssertNil(objectID as Any?) } } } @@ -427,10 +427,10 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = stack.fetchOne(from, fetchClauses) + let object = try stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) - let objectID = stack.fetchObjectID(from, fetchClauses) + let objectID = try stack.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) // configuration ambiguous, no other behavior should be relied on @@ -441,10 +441,10 @@ final class FetchTests: BaseTestDataTestCase { Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] - let object = stack.fetchOne(from, fetchClauses) + let object = try stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) - let objectID = stack.fetchObjectID(from, fetchClauses) + let objectID = try stack.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) // configuration ambiguous, no other behavior should be relied on @@ -455,10 +455,10 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = stack.fetchOne(from, fetchClauses) + let object = try stack.fetchOne(from, fetchClauses) XCTAssertNil(object) - let objectID = stack.fetchObjectID(from, fetchClauses) + let objectID = try stack.fetchObjectID(from, fetchClauses) XCTAssertNil(objectID) } } @@ -471,11 +471,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = stack.fetchOne(from, fetchClauses) + let object = try stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testString, "nil:TestEntity1:2") - let objectID = stack.fetchObjectID(from, fetchClauses) + let objectID = try stack.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -485,11 +485,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] - let object = stack.fetchOne(from, fetchClauses) + let object = try stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testString, "nil:TestEntity1:3") - let objectID = stack.fetchObjectID(from, fetchClauses) + let objectID = try stack.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -499,10 +499,10 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = stack.fetchOne(from, fetchClauses) + let object = try stack.fetchOne(from, fetchClauses) XCTAssertNil(object) - let objectID = stack.fetchObjectID(from, fetchClauses) + let objectID = try stack.fetchObjectID(from, fetchClauses) XCTAssertNil(objectID) } } @@ -515,11 +515,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = stack.fetchOne(from, fetchClauses) + let object = try stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testString, "Config1:TestEntity1:2") - let objectID = stack.fetchObjectID(from, fetchClauses) + let objectID = try stack.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -529,11 +529,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] - let object = stack.fetchOne(from, fetchClauses) + let object = try stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testString, "Config1:TestEntity1:3") - let objectID = stack.fetchObjectID(from, fetchClauses) + let objectID = try stack.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -543,10 +543,10 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = stack.fetchOne(from, fetchClauses) + let object = try stack.fetchOne(from, fetchClauses) XCTAssertNil(object) - let objectID = stack.fetchObjectID(from, fetchClauses) + let objectID = try stack.fetchObjectID(from, fetchClauses) XCTAssertNil(objectID) } } @@ -559,17 +559,17 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = self.expectLogger([.logWarning]) { + let object = try? self.expectLogger([.logError]) { - stack.fetchOne(from, fetchClauses) + try stack.fetchOne(from, fetchClauses) } - XCTAssertNil(object) + XCTAssertNil(object as Any?) - let objectID = self.expectLogger([.logWarning]) { + let objectID = try? self.expectLogger([.logError]) { - stack.fetchObjectID(from, fetchClauses) + try stack.fetchObjectID(from, fetchClauses) } - XCTAssertNil(objectID) + XCTAssertNil(objectID as Any?) } do { @@ -577,17 +577,17 @@ final class FetchTests: BaseTestDataTestCase { Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] - let object = self.expectLogger([.logWarning]) { + let object = try? self.expectLogger([.logError]) { - stack.fetchOne(from, fetchClauses) + try stack.fetchOne(from, fetchClauses) } - XCTAssertNil(object) + XCTAssertNil(object as Any?) - let objectID = self.expectLogger([.logWarning]) { + let objectID = try? self.expectLogger([.logError]) { - stack.fetchObjectID(from, fetchClauses) + try stack.fetchObjectID(from, fetchClauses) } - XCTAssertNil(objectID) + XCTAssertNil(objectID as Any?) } } } @@ -610,10 +610,10 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = stack.fetchOne(from, fetchClauses) + let object = try stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) - let objectID = stack.fetchObjectID(from, fetchClauses) + let objectID = try stack.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) // configuration ambiguous, no other behavior should be relied on @@ -624,10 +624,10 @@ final class FetchTests: BaseTestDataTestCase { Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] - let object = stack.fetchOne(from, fetchClauses) + let object = try stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) - let objectID = stack.fetchObjectID(from, fetchClauses) + let objectID = try stack.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) // configuration ambiguous, no other behavior should be relied on @@ -638,10 +638,10 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = stack.fetchOne(from, fetchClauses) + let object = try stack.fetchOne(from, fetchClauses) XCTAssertNil(object) - let objectID = stack.fetchObjectID(from, fetchClauses) + let objectID = try stack.fetchObjectID(from, fetchClauses) XCTAssertNil(objectID) } } @@ -654,11 +654,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = stack.fetchOne(from, fetchClauses) + let object = try stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testString, "nil:TestEntity1:2") - let objectID = stack.fetchObjectID(from, fetchClauses) + let objectID = try stack.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -668,11 +668,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] - let object = stack.fetchOne(from, fetchClauses) + let object = try stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testString, "nil:TestEntity1:3") - let objectID = stack.fetchObjectID(from, fetchClauses) + let objectID = try stack.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -682,10 +682,10 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = stack.fetchOne(from, fetchClauses) + let object = try stack.fetchOne(from, fetchClauses) XCTAssertNil(object) - let objectID = stack.fetchObjectID(from, fetchClauses) + let objectID = try stack.fetchObjectID(from, fetchClauses) XCTAssertNil(objectID) } } @@ -698,11 +698,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = stack.fetchOne(from, fetchClauses) + let object = try stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testString, "Config1:TestEntity1:2") - let objectID = stack.fetchObjectID(from, fetchClauses) + let objectID = try stack.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -712,11 +712,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] - let object = stack.fetchOne(from, fetchClauses) + let object = try stack.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testString, "Config1:TestEntity1:3") - let objectID = stack.fetchObjectID(from, fetchClauses) + let objectID = try stack.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -726,10 +726,10 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = stack.fetchOne(from, fetchClauses) + let object = try stack.fetchOne(from, fetchClauses) XCTAssertNil(object) - let objectID = stack.fetchObjectID(from, fetchClauses) + let objectID = try stack.fetchObjectID(from, fetchClauses) XCTAssertNil(objectID) } } @@ -754,23 +754,21 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = stack.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 3) + let objects = try stack.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 3) XCTAssertEqual( - (objects ?? []).map { $0.testString ?? "" }, + objects.map { $0.testString ?? "" }, [ "nil:TestEntity1:2", "nil:TestEntity1:3", "nil:TestEntity1:4" ] ) - let objectIDs = stack.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 3) + let objectIDs = try stack.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 3) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -780,23 +778,21 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = stack.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 3) + let objects = try stack.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 3) XCTAssertEqual( - (objects ?? []).map { $0.testString ?? "" }, + objects.map { $0.testString ?? "" }, [ "nil:TestEntity1:4", "nil:TestEntity1:3", "nil:TestEntity1:2" ] ) - let objectIDs = stack.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 3) + let objectIDs = try stack.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 3) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -805,13 +801,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let objects = stack.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 0) + let objects = try stack.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 0) - let objectIDs = stack.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 0) + let objectIDs = try stack.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 0) } } do { @@ -824,23 +818,21 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = stack.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 3) + let objects = try stack.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 3) XCTAssertEqual( - (objects ?? []).map { $0.testString ?? "" }, + objects.map { $0.testString ?? "" }, [ "nil:TestEntity1:2", "nil:TestEntity1:3", "nil:TestEntity1:4" ] ) - let objectIDs = stack.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 3) + let objectIDs = try stack.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 3) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -850,23 +842,21 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = stack.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 3) + let objects = try stack.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 3) XCTAssertEqual( - (objects ?? []).map { $0.testString ?? "" }, + objects.map { $0.testString ?? "" }, [ "nil:TestEntity1:4", "nil:TestEntity1:3", "nil:TestEntity1:2" ] ) - let objectIDs = stack.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 3) + let objectIDs = try stack.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 3) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -875,13 +865,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let objects = stack.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 0) + let objects = try stack.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 0) - let objectIDs = stack.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 0) + let objectIDs = try stack.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 0) } } do { @@ -893,15 +881,15 @@ final class FetchTests: BaseTestDataTestCase { Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let objects = self.expectLogger([.logWarning]) { + let objects = try? self.expectLogger([.logError]) { - stack.fetchAll(from, fetchClauses) + try stack.fetchAll(from, fetchClauses) } XCTAssertNil(objects) - let objectIDs = self.expectLogger([.logWarning]) { + let objectIDs = try? self.expectLogger([.logError]) { - stack.fetchObjectIDs(from, fetchClauses) + try stack.fetchObjectIDs(from, fetchClauses) } XCTAssertNil(objectIDs) } @@ -911,15 +899,15 @@ final class FetchTests: BaseTestDataTestCase { Where(#keyPath(TestEntity1.testNumber), isEqualTo: 0), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] - let objects = self.expectLogger([.logWarning]) { + let objects = try? self.expectLogger([.logError]) { - stack.fetchAll(from, fetchClauses) + try stack.fetchAll(from, fetchClauses) } XCTAssertNil(objects) - let objectIDs = self.expectLogger([.logWarning]) { + let objectIDs = try? self.expectLogger([.logError]) { - stack.fetchObjectIDs(from, fetchClauses) + try stack.fetchObjectIDs(from, fetchClauses) } XCTAssertNil(objectIDs) } @@ -929,15 +917,15 @@ final class FetchTests: BaseTestDataTestCase { Where(#keyPath(TestEntity1.testNumber), isEqualTo: nil), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] - let objects = self.expectLogger([.logWarning]) { + let objects = try? self.expectLogger([.logError]) { - stack.fetchAll(from, fetchClauses) + try stack.fetchAll(from, fetchClauses) } XCTAssertNil(objects) - let objectIDs = self.expectLogger([.logWarning]) { + let objectIDs = try? self.expectLogger([.logError]) { - stack.fetchObjectIDs(from, fetchClauses) + try stack.fetchObjectIDs(from, fetchClauses) } XCTAssertNil(objectIDs) } @@ -963,13 +951,11 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = stack.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 3) + let objects = try stack.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 3) - let objectIDs = stack.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 3) + let objectIDs = try stack.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 3) // configuration ambiguous, no other behavior should be relied on } @@ -980,13 +966,11 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = stack.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 3) + let objects = try stack.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 3) - let objectIDs = stack.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 3) + let objectIDs = try stack.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 3) // configuration ambiguous, no other behavior should be relied on } @@ -996,13 +980,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let objects = stack.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 0) + let objects = try stack.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 0) - let objectIDs = stack.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 0) + let objectIDs = try stack.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 0) } } do { @@ -1015,22 +997,20 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = stack.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 2) + let objects = try stack.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 2) XCTAssertEqual( - (objects ?? []).map { $0.testString ?? "" }, + objects.map { $0.testString ?? "" }, [ "nil:TestEntity1:4", "nil:TestEntity1:5" ] ) - let objectIDs = stack.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 2) + let objectIDs = try stack.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 2) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -1040,22 +1020,20 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = stack.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 2) + let objects = try stack.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 2) XCTAssertEqual( - (objects ?? []).map { $0.testString ?? "" }, + objects.map { $0.testString ?? "" }, [ "nil:TestEntity1:2", "nil:TestEntity1:1" ] ) - let objectIDs = stack.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 2) + let objectIDs = try stack.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 2) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -1064,13 +1042,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let objects = stack.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 0) + let objects = try stack.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 0) - let objectIDs = stack.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 0) + let objectIDs = try stack.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 0) } } do { @@ -1083,22 +1059,20 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = stack.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 2) + let objects = try stack.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 2) XCTAssertEqual( - (objects ?? []).map { $0.testString ?? "" }, + objects.map { $0.testString ?? "" }, [ "Config1:TestEntity1:4", "Config1:TestEntity1:5" ] ) - let objectIDs = stack.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 2) + let objectIDs = try stack.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 2) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -1108,22 +1082,20 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = stack.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 2) + let objects = try stack.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 2) XCTAssertEqual( - (objects ?? []).map { $0.testString ?? "" }, + objects.map { $0.testString ?? "" }, [ "Config1:TestEntity1:2", "Config1:TestEntity1:1" ] ) - let objectIDs = stack.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 2) + let objectIDs = try stack.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 2) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -1132,13 +1104,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let objects = stack.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 0) + let objects = try stack.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 0) - let objectIDs = stack.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 0) + let objectIDs = try stack.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 0) } } do { @@ -1149,15 +1119,15 @@ final class FetchTests: BaseTestDataTestCase { let fetchClauses: [FetchClause] = [ OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let objects = self.expectLogger([.logWarning]) { + let objects = try? self.expectLogger([.logError]) { - stack.fetchAll(from, fetchClauses) + try stack.fetchAll(from, fetchClauses) } XCTAssertNil(objects) - let objectIDs = self.expectLogger([.logWarning]) { + let objectIDs = try? self.expectLogger([.logError]) { - stack.fetchObjectIDs(from, fetchClauses) + try stack.fetchObjectIDs(from, fetchClauses) } XCTAssertNil(objectIDs) } @@ -1166,15 +1136,15 @@ final class FetchTests: BaseTestDataTestCase { let fetchClauses: [FetchClause] = [ OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] - let objects = self.expectLogger([.logWarning]) { + let objects = try? self.expectLogger([.logError]) { - stack.fetchAll(from, fetchClauses) + try stack.fetchAll(from, fetchClauses) } XCTAssertNil(objects) - let objectIDs = self.expectLogger([.logWarning]) { + let objectIDs = try? self.expectLogger([.logError]) { - stack.fetchObjectIDs(from, fetchClauses) + try stack.fetchObjectIDs(from, fetchClauses) } XCTAssertNil(objectIDs) } @@ -1200,13 +1170,11 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = stack.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 3) + let objects = try stack.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 3) - let objectIDs = stack.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 3) + let objectIDs = try stack.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 3) // configuration ambiguous, no other behavior should be relied on } @@ -1217,13 +1185,11 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = stack.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 3) + let objects = try stack.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 3) - let objectIDs = stack.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 3) + let objectIDs = try stack.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 3) // configuration ambiguous, no other behavior should be relied on } @@ -1233,13 +1199,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let objects = stack.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 0) + let objects = try stack.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 0) - let objectIDs = stack.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 0) + let objectIDs = try stack.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 0) } } do { @@ -1252,22 +1216,20 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = stack.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 2) + let objects = try stack.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 2) XCTAssertEqual( - (objects ?? []).map { $0.testString ?? "" }, + objects.map { $0.testString ?? "" }, [ "nil:TestEntity1:4", "nil:TestEntity1:5" ] ) - let objectIDs = stack.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 2) + let objectIDs = try stack.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 2) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -1277,22 +1239,20 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = stack.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 2) + let objects = try stack.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 2) XCTAssertEqual( - (objects ?? []).map { $0.testString ?? "" }, + objects.map { $0.testString ?? "" }, [ "nil:TestEntity1:2", "nil:TestEntity1:1" ] ) - let objectIDs = stack.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 2) + let objectIDs = try stack.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 2) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -1301,13 +1261,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let objects = stack.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 0) + let objects = try stack.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 0) - let objectIDs = stack.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 0) + let objectIDs = try stack.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 0) } } do { @@ -1320,22 +1278,20 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = stack.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 2) + let objects = try stack.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 2) XCTAssertEqual( - (objects ?? []).map { $0.testString ?? "" }, + objects.map { $0.testString ?? "" }, [ "Config1:TestEntity1:4", "Config1:TestEntity1:5" ] ) - let objectIDs = stack.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 2) + let objectIDs = try stack.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 2) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -1345,22 +1301,20 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = stack.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 2) + let objects = try stack.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 2) XCTAssertEqual( - (objects ?? []).map { $0.testString ?? "" }, + objects.map { $0.testString ?? "" }, [ "Config1:TestEntity1:2", "Config1:TestEntity1:1" ] ) - let objectIDs = stack.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 2) + let objectIDs = try stack.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 2) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -1369,13 +1323,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let objects = stack.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 0) + let objects = try stack.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 0) - let objectIDs = stack.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 0) + let objectIDs = try stack.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 0) } } } @@ -1394,34 +1346,31 @@ final class FetchTests: BaseTestDataTestCase { let from = From() do { - let count = stack.fetchCount( + let count = try stack.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 3) } do { - let count = stack.fetchCount( + let count = try stack.fetchCount( from, Where("%K < %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 3) } do { - let count = stack.fetchCount( + let count = try stack.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) - XCTAssertNotNil(count) XCTAssertEqual(count, 0) } } @@ -1430,34 +1379,31 @@ final class FetchTests: BaseTestDataTestCase { let from = From(nil) do { - let count = stack.fetchCount( + let count = try stack.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 3) } do { - let count = stack.fetchCount( + let count = try stack.fetchCount( from, Where("%K < %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 3) } do { - let count = stack.fetchCount( + let count = try stack.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) - XCTAssertNotNil(count) XCTAssertEqual(count, 0) } } @@ -1466,9 +1412,9 @@ final class FetchTests: BaseTestDataTestCase { let from = From("Config1") do { - let count = self.expectLogger([.logWarning]) { + let count = try? self.expectLogger([.logError]) { - stack.fetchCount( + try stack.fetchCount( from, Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) @@ -1478,9 +1424,9 @@ final class FetchTests: BaseTestDataTestCase { } do { - let count = self.expectLogger([.logWarning]) { + let count = try? self.expectLogger([.logError]) { - stack.fetchCount( + try stack.fetchCount( from, Where(#keyPath(TestEntity1.testNumber), isEqualTo: 0), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) @@ -1490,9 +1436,9 @@ final class FetchTests: BaseTestDataTestCase { } do { - let count = self.expectLogger([.logWarning]) { + let count = try? self.expectLogger([.logError]) { - stack.fetchCount( + try stack.fetchCount( from, Where(#keyPath(TestEntity1.testNumber), isEqualTo: nil), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) @@ -1517,34 +1463,31 @@ final class FetchTests: BaseTestDataTestCase { let from = From() do { - let count = stack.fetchCount( + let count = try stack.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 3) } do { - let count = stack.fetchCount( + let count = try stack.fetchCount( from, Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 3) } do { - let count = stack.fetchCount( + let count = try stack.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) - XCTAssertNotNil(count) XCTAssertEqual(count, 0) } } @@ -1553,34 +1496,31 @@ final class FetchTests: BaseTestDataTestCase { let from = From(nil) do { - let count = stack.fetchCount( + let count = try stack.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 2) } do { - let count = stack.fetchCount( + let count = try stack.fetchCount( from, Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 2) } do { - let count = stack.fetchCount( + let count = try stack.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) - XCTAssertNotNil(count) XCTAssertEqual(count, 0) } } @@ -1589,34 +1529,31 @@ final class FetchTests: BaseTestDataTestCase { let from = From("Config1") do { - let count = stack.fetchCount( + let count = try stack.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 2) } do { - let count = stack.fetchCount( + let count = try stack.fetchCount( from, Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 2) } do { - let count = stack.fetchCount( + let count = try stack.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) - XCTAssertNotNil(count) XCTAssertEqual(count, 0) } } @@ -1625,9 +1562,9 @@ final class FetchTests: BaseTestDataTestCase { let from = From("Config2") do { - let count = self.expectLogger([.logWarning]) { + let count = try? self.expectLogger([.logError]) { - stack.fetchCount( + try stack.fetchCount( from, Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) @@ -1637,9 +1574,9 @@ final class FetchTests: BaseTestDataTestCase { } do { - let count = self.expectLogger([.logWarning]) { + let count = try? self.expectLogger([.logError]) { - stack.fetchCount( + try stack.fetchCount( from, Where(#keyPath(TestEntity1.testNumber), isEqualTo: 0), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) @@ -1649,9 +1586,9 @@ final class FetchTests: BaseTestDataTestCase { } do { - let count = self.expectLogger([.logWarning]) { + let count = try? self.expectLogger([.logError]) { - stack.fetchCount( + try stack.fetchCount( from, Where(#keyPath(TestEntity1.testNumber), isEqualTo: nil), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) @@ -1676,34 +1613,31 @@ final class FetchTests: BaseTestDataTestCase { let from = From(nil, "Config1") do { - let count = stack.fetchCount( + let count = try stack.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 3) } do { - let count = stack.fetchCount( + let count = try stack.fetchCount( from, Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 3) } do { - let count = stack.fetchCount( + let count = try stack.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) - XCTAssertNotNil(count) XCTAssertEqual(count, 0) } } @@ -1712,34 +1646,31 @@ final class FetchTests: BaseTestDataTestCase { let from = From(nil, "Config2") do { - let count = stack.fetchCount( + let count = try stack.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 2) } do { - let count = stack.fetchCount( + let count = try stack.fetchCount( from, Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 2) } do { - let count = stack.fetchCount( + let count = try stack.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) - XCTAssertNotNil(count) XCTAssertEqual(count, 0) } } @@ -1748,34 +1679,31 @@ final class FetchTests: BaseTestDataTestCase { let from = From("Config1", "Config2") do { - let count = stack.fetchCount( + let count = try stack.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 2) } do { - let count = stack.fetchCount( + let count = try stack.fetchCount( from, Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 2) } do { - let count = stack.fetchCount( + let count = try stack.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) - XCTAssertNotNil(count) XCTAssertEqual(count, 0) } } @@ -1799,11 +1727,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = transaction.fetchOne(from, fetchClauses) + let object = try transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testString, "nil:TestEntity1:2") - let objectID = transaction.fetchObjectID(from, fetchClauses) + let objectID = try transaction.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -1813,11 +1741,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] - let object = transaction.fetchOne(from, fetchClauses) + let object = try transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testString, "nil:TestEntity1:3") - let objectID = transaction.fetchObjectID(from, fetchClauses) + let objectID = try transaction.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -1827,10 +1755,10 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = transaction.fetchOne(from, fetchClauses) + let object = try transaction.fetchOne(from, fetchClauses) XCTAssertNil(object) - let objectID = transaction.fetchObjectID(from, fetchClauses) + let objectID = try transaction.fetchObjectID(from, fetchClauses) XCTAssertNil(objectID) } try transaction.cancel() @@ -1846,11 +1774,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = transaction.fetchOne(from, fetchClauses) + let object = try transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testString, "nil:TestEntity1:2") - let objectID = transaction.fetchObjectID(from, fetchClauses) + let objectID = try transaction.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -1860,11 +1788,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] - let object = transaction.fetchOne(from, fetchClauses) + let object = try transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testString, "nil:TestEntity1:3") - let objectID = transaction.fetchObjectID(from, fetchClauses) + let objectID = try transaction.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -1874,10 +1802,10 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = transaction.fetchOne(from, fetchClauses) + let object = try transaction.fetchOne(from, fetchClauses) XCTAssertNil(object) - let objectID = transaction.fetchObjectID(from, fetchClauses) + let objectID = try transaction.fetchObjectID(from, fetchClauses) XCTAssertNil(objectID) } try transaction.cancel() @@ -1893,17 +1821,17 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = self.expectLogger([.logWarning]) { + let object = try? self.expectLogger([.logError]) { - transaction.fetchOne(from, fetchClauses) + try transaction.fetchOne(from, fetchClauses) } - XCTAssertNil(object) + XCTAssertNil(object as Any?) - let objectID = self.expectLogger([.logWarning]) { + let objectID = try? self.expectLogger([.logError]) { - transaction.fetchObjectID(from, fetchClauses) + try transaction.fetchObjectID(from, fetchClauses) } - XCTAssertNil(objectID) + XCTAssertNil(objectID as Any?) } do { @@ -1911,17 +1839,17 @@ final class FetchTests: BaseTestDataTestCase { Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] - let object = self.expectLogger([.logWarning]) { + let object = try? self.expectLogger([.logError]) { - transaction.fetchOne(from, fetchClauses) + try transaction.fetchOne(from, fetchClauses) } - XCTAssertNil(object) + XCTAssertNil(object as Any?) - let objectID = self.expectLogger([.logWarning]) { + let objectID = try? self.expectLogger([.logError]) { - transaction.fetchObjectID(from, fetchClauses) + try transaction.fetchObjectID(from, fetchClauses) } - XCTAssertNil(objectID) + XCTAssertNil(objectID as Any?) } try transaction.cancel() } @@ -1946,11 +1874,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = transaction.fetchOne(from, fetchClauses) + let object = try transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testNumber, 2) // configuration ambiguous - let objectID = transaction.fetchObjectID(from, fetchClauses) + let objectID = try transaction.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -1960,11 +1888,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] - let object = transaction.fetchOne(from, fetchClauses) + let object = try transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testNumber, 3) // configuration - let objectID = transaction.fetchObjectID(from, fetchClauses) + let objectID = try transaction.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -1974,10 +1902,10 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = transaction.fetchOne(from, fetchClauses) + let object = try transaction.fetchOne(from, fetchClauses) XCTAssertNil(object) - let objectID = transaction.fetchObjectID(from, fetchClauses) + let objectID = try transaction.fetchObjectID(from, fetchClauses) XCTAssertNil(objectID) } try transaction.cancel() @@ -1993,11 +1921,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = transaction.fetchOne(from, fetchClauses) + let object = try transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testString, "nil:TestEntity1:2") - let objectID = transaction.fetchObjectID(from, fetchClauses) + let objectID = try transaction.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -2007,11 +1935,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] - let object = transaction.fetchOne(from, fetchClauses) + let object = try transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testString, "nil:TestEntity1:3") - let objectID = transaction.fetchObjectID(from, fetchClauses) + let objectID = try transaction.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -2021,10 +1949,10 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = transaction.fetchOne(from, fetchClauses) + let object = try transaction.fetchOne(from, fetchClauses) XCTAssertNil(object) - let objectID = transaction.fetchObjectID(from, fetchClauses) + let objectID = try transaction.fetchObjectID(from, fetchClauses) XCTAssertNil(objectID) } try transaction.cancel() @@ -2040,11 +1968,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = transaction.fetchOne(from, fetchClauses) + let object = try transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testString, "Config1:TestEntity1:2") - let objectID = transaction.fetchObjectID(from, fetchClauses) + let objectID = try transaction.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -2054,11 +1982,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] - let object = transaction.fetchOne(from, fetchClauses) + let object = try transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testString, "Config1:TestEntity1:3") - let objectID = transaction.fetchObjectID(from, fetchClauses) + let objectID = try transaction.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -2068,10 +1996,10 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = transaction.fetchOne(from, fetchClauses) + let object = try transaction.fetchOne(from, fetchClauses) XCTAssertNil(object) - let objectID = transaction.fetchObjectID(from, fetchClauses) + let objectID = try transaction.fetchObjectID(from, fetchClauses) XCTAssertNil(objectID) } try transaction.cancel() @@ -2087,17 +2015,17 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = self.expectLogger([.logWarning]) { + let object = try? self.expectLogger([.logError]) { - transaction.fetchOne(from, fetchClauses) + try transaction.fetchOne(from, fetchClauses) } - XCTAssertNil(object) + XCTAssertNil(object as Any?) - let objectID = self.expectLogger([.logWarning]) { + let objectID = try? self.expectLogger([.logError]) { - transaction.fetchObjectID(from, fetchClauses) + try transaction.fetchObjectID(from, fetchClauses) } - XCTAssertNil(objectID) + XCTAssertNil(objectID as Any?) } do { @@ -2105,17 +2033,17 @@ final class FetchTests: BaseTestDataTestCase { Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] - let object = self.expectLogger([.logWarning]) { + let object = try? self.expectLogger([.logError]) { - transaction.fetchOne(from, fetchClauses) + try transaction.fetchOne(from, fetchClauses) } - XCTAssertNil(object) + XCTAssertNil(object as Any?) - let objectID = self.expectLogger([.logWarning]) { + let objectID = try? self.expectLogger([.logError]) { - transaction.fetchObjectID(from, fetchClauses) + try transaction.fetchObjectID(from, fetchClauses) } - XCTAssertNil(objectID) + XCTAssertNil(objectID as Any?) } try transaction.cancel() } @@ -2140,11 +2068,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = transaction.fetchOne(from, fetchClauses) + let object = try transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testNumber, 2) // configuration is ambiguous - let objectID = transaction.fetchObjectID(from, fetchClauses) + let objectID = try transaction.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -2154,11 +2082,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] - let object = transaction.fetchOne(from, fetchClauses) + let object = try transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testNumber, 3) // configuration is ambiguous - let objectID = transaction.fetchObjectID(from, fetchClauses) + let objectID = try transaction.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -2168,10 +2096,10 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = transaction.fetchOne(from, fetchClauses) + let object = try transaction.fetchOne(from, fetchClauses) XCTAssertNil(object) - let objectID = transaction.fetchObjectID(from, fetchClauses) + let objectID = try transaction.fetchObjectID(from, fetchClauses) XCTAssertNil(objectID) } try transaction.cancel() @@ -2187,11 +2115,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = transaction.fetchOne(from, fetchClauses) + let object = try transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testString, "nil:TestEntity1:2") - let objectID = transaction.fetchObjectID(from, fetchClauses) + let objectID = try transaction.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -2201,11 +2129,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] - let object = transaction.fetchOne(from, fetchClauses) + let object = try transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testString, "nil:TestEntity1:3") - let objectID = transaction.fetchObjectID(from, fetchClauses) + let objectID = try transaction.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -2215,10 +2143,10 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = transaction.fetchOne(from, fetchClauses) + let object = try transaction.fetchOne(from, fetchClauses) XCTAssertNil(object) - let objectID = transaction.fetchObjectID(from, fetchClauses) + let objectID = try transaction.fetchObjectID(from, fetchClauses) XCTAssertNil(objectID) } try transaction.cancel() @@ -2234,11 +2162,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = transaction.fetchOne(from, fetchClauses) + let object = try transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testString, "Config1:TestEntity1:2") - let objectID = transaction.fetchObjectID(from, fetchClauses) + let objectID = try transaction.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -2248,11 +2176,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] - let object = transaction.fetchOne(from, fetchClauses) + let object = try transaction.fetchOne(from, fetchClauses) XCTAssertNotNil(object) XCTAssertEqual(object?.testString, "Config1:TestEntity1:3") - let objectID = transaction.fetchObjectID(from, fetchClauses) + let objectID = try transaction.fetchObjectID(from, fetchClauses) XCTAssertNotNil(objectID) XCTAssertEqual(objectID, object?.objectID) } @@ -2262,10 +2190,10 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let object = transaction.fetchOne(from, fetchClauses) + let object = try transaction.fetchOne(from, fetchClauses) XCTAssertNil(object) - let objectID = transaction.fetchObjectID(from, fetchClauses) + let objectID = try transaction.fetchObjectID(from, fetchClauses) XCTAssertNil(objectID) } try transaction.cancel() @@ -2292,23 +2220,21 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = transaction.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 3) + let objects = try transaction.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 3) XCTAssertEqual( - (objects ?? []).map { $0.testString ?? "" }, + objects.map { $0.testString ?? "" }, [ "nil:TestEntity1:2", "nil:TestEntity1:3", "nil:TestEntity1:4" ] ) - let objectIDs = transaction.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 3) + let objectIDs = try transaction.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 3) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -2318,23 +2244,21 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = transaction.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 3) + let objects = try transaction.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 3) XCTAssertEqual( - (objects ?? []).map { $0.testString ?? "" }, + objects.map { $0.testString ?? "" }, [ "nil:TestEntity1:4", "nil:TestEntity1:3", "nil:TestEntity1:2" ] ) - let objectIDs = transaction.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 3) + let objectIDs = try transaction.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 3) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -2343,13 +2267,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let objects = transaction.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 0) + let objects = try transaction.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 0) - let objectIDs = transaction.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 0) + let objectIDs = try transaction.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 0) } try transaction.cancel() } @@ -2365,23 +2287,21 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = transaction.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 3) + let objects = try transaction.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 3) XCTAssertEqual( - (objects ?? []).map { $0.testString ?? "" }, + objects.map { $0.testString ?? "" }, [ "nil:TestEntity1:2", "nil:TestEntity1:3", "nil:TestEntity1:4" ] ) - let objectIDs = transaction.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 3) + let objectIDs = try transaction.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 3) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -2391,23 +2311,21 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = transaction.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 3) + let objects = try transaction.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 3) XCTAssertEqual( - (objects ?? []).map { $0.testString ?? "" }, + objects.map { $0.testString ?? "" }, [ "nil:TestEntity1:4", "nil:TestEntity1:3", "nil:TestEntity1:2" ] ) - let objectIDs = transaction.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 3) + let objectIDs = try transaction.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 3) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -2416,13 +2334,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let objects = transaction.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 0) + let objects = try transaction.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 0) - let objectIDs = transaction.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 0) + let objectIDs = try transaction.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 0) } try transaction.cancel() } @@ -2437,15 +2353,15 @@ final class FetchTests: BaseTestDataTestCase { Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let objects = self.expectLogger([.logWarning]) { + let objects = try? self.expectLogger([.logError]) { - transaction.fetchAll(from, fetchClauses) + try transaction.fetchAll(from, fetchClauses) } XCTAssertNil(objects) - let objectIDs = self.expectLogger([.logWarning]) { + let objectIDs = try? self.expectLogger([.logError]) { - transaction.fetchObjectIDs(from, fetchClauses) + try transaction.fetchObjectIDs(from, fetchClauses) } XCTAssertNil(objectIDs) } @@ -2455,15 +2371,15 @@ final class FetchTests: BaseTestDataTestCase { Where(#keyPath(TestEntity1.testNumber), isEqualTo: 0), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] - let objects = self.expectLogger([.logWarning]) { + let objects = try? self.expectLogger([.logError]) { - transaction.fetchAll(from, fetchClauses) + try transaction.fetchAll(from, fetchClauses) } XCTAssertNil(objects) - let objectIDs = self.expectLogger([.logWarning]) { + let objectIDs = try? self.expectLogger([.logError]) { - transaction.fetchObjectIDs(from, fetchClauses) + try transaction.fetchObjectIDs(from, fetchClauses) } XCTAssertNil(objectIDs) } @@ -2473,15 +2389,15 @@ final class FetchTests: BaseTestDataTestCase { Where(#keyPath(TestEntity1.testNumber), isEqualTo: nil), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] - let objects = self.expectLogger([.logWarning]) { + let objects = try? self.expectLogger([.logError]) { - transaction.fetchAll(from, fetchClauses) + try transaction.fetchAll(from, fetchClauses) } XCTAssertNil(objects) - let objectIDs = self.expectLogger([.logWarning]) { + let objectIDs = try? self.expectLogger([.logError]) { - transaction.fetchObjectIDs(from, fetchClauses) + try transaction.fetchObjectIDs(from, fetchClauses) } XCTAssertNil(objectIDs) } @@ -2509,20 +2425,18 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = transaction.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 3) + let objects = try transaction.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 3) XCTAssertEqual( - Set((objects ?? []).map { $0.testNumber!.intValue }), + Set(objects.map { $0.testNumber!.intValue }), [4, 5] as Set ) // configuration is ambiguous - let objectIDs = transaction.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 3) + let objectIDs = try transaction.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 3) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -2532,20 +2446,18 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = transaction.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 3) + let objects = try transaction.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 3) XCTAssertEqual( - Set((objects ?? []).map { $0.testNumber!.intValue }), + Set(objects.map { $0.testNumber!.intValue }), [1, 2] as Set ) // configuration is ambiguous - let objectIDs = transaction.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 3) + let objectIDs = try transaction.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 3) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -2554,13 +2466,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let objects = transaction.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 0) + let objects = try transaction.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 0) - let objectIDs = transaction.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 0) + let objectIDs = try transaction.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 0) } try transaction.cancel() } @@ -2576,22 +2486,20 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = transaction.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 2) + let objects = try transaction.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 2) XCTAssertEqual( - (objects ?? []).map { $0.testString ?? "" }, + objects.map { $0.testString ?? "" }, [ "nil:TestEntity1:4", "nil:TestEntity1:5" ] ) - let objectIDs = transaction.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 2) + let objectIDs = try transaction.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 2) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -2601,22 +2509,20 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = transaction.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 2) + let objects = try transaction.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 2) XCTAssertEqual( - (objects ?? []).map { $0.testString ?? "" }, + objects.map { $0.testString ?? "" }, [ "nil:TestEntity1:2", "nil:TestEntity1:1" ] ) - let objectIDs = transaction.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 2) + let objectIDs = try transaction.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 2) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -2625,13 +2531,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let objects = transaction.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 0) + let objects = try transaction.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 0) - let objectIDs = transaction.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 0) + let objectIDs = try transaction.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 0) } try transaction.cancel() } @@ -2647,22 +2551,20 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = transaction.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 2) + let objects = try transaction.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 2) XCTAssertEqual( - (objects ?? []).map { $0.testString ?? "" }, + objects.map { $0.testString ?? "" }, [ "Config1:TestEntity1:4", "Config1:TestEntity1:5" ] ) - let objectIDs = transaction.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 2) + let objectIDs = try transaction.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 2) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -2672,22 +2574,20 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = transaction.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 2) + let objects = try transaction.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 2) XCTAssertEqual( - (objects ?? []).map { $0.testString ?? "" }, + objects.map { $0.testString ?? "" }, [ "Config1:TestEntity1:2", "Config1:TestEntity1:1" ] ) - let objectIDs = transaction.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 2) + let objectIDs = try transaction.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 2) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -2696,13 +2596,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let objects = transaction.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 0) + let objects = try transaction.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 0) - let objectIDs = transaction.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 0) + let objectIDs = try transaction.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 0) } try transaction.cancel() } @@ -2716,15 +2614,15 @@ final class FetchTests: BaseTestDataTestCase { let fetchClauses: [FetchClause] = [ OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let objects = self.expectLogger([.logWarning]) { + let objects = try? self.expectLogger([.logError]) { - transaction.fetchAll(from, fetchClauses) + try transaction.fetchAll(from, fetchClauses) } XCTAssertNil(objects) - let objectIDs = self.expectLogger([.logWarning]) { + let objectIDs = try? self.expectLogger([.logError]) { - transaction.fetchObjectIDs(from, fetchClauses) + try transaction.fetchObjectIDs(from, fetchClauses) } XCTAssertNil(objectIDs) } @@ -2733,15 +2631,15 @@ final class FetchTests: BaseTestDataTestCase { let fetchClauses: [FetchClause] = [ OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) ] - let objects = self.expectLogger([.logWarning]) { + let objects = try? self.expectLogger([.logError]) { - transaction.fetchAll(from, fetchClauses) + try transaction.fetchAll(from, fetchClauses) } XCTAssertNil(objects) - let objectIDs = self.expectLogger([.logWarning]) { + let objectIDs = try? self.expectLogger([.logError]) { - transaction.fetchObjectIDs(from, fetchClauses) + try transaction.fetchObjectIDs(from, fetchClauses) } XCTAssertNil(objectIDs) } @@ -2769,20 +2667,18 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = transaction.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 3) + let objects = try transaction.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 3) XCTAssertEqual( - Set((objects ?? []).map { $0.testNumber!.intValue }), + Set(objects.map { $0.testNumber!.intValue }), [4, 5] as Set ) // configuration is ambiguous - let objectIDs = transaction.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 3) + let objectIDs = try transaction.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 3) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -2792,20 +2688,18 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = transaction.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 3) + let objects = try transaction.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 3) XCTAssertEqual( - Set((objects ?? []).map { $0.testNumber!.intValue }), + Set(objects.map { $0.testNumber!.intValue }), [1, 2] as Set ) // configuration is ambiguous - let objectIDs = transaction.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 3) + let objectIDs = try transaction.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 3) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -2814,13 +2708,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let objects = transaction.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 0) + let objects = try transaction.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 0) - let objectIDs = transaction.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 0) + let objectIDs = try transaction.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 0) } try transaction.cancel() } @@ -2836,22 +2728,20 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = transaction.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 2) + let objects = try transaction.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 2) XCTAssertEqual( - (objects ?? []).map { $0.testString ?? "" }, + objects.map { $0.testString ?? "" }, [ "nil:TestEntity1:4", "nil:TestEntity1:5" ] ) - let objectIDs = transaction.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 2) + let objectIDs = try transaction.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 2) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -2861,22 +2751,20 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = transaction.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 2) + let objects = try transaction.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 2) XCTAssertEqual( - (objects ?? []).map { $0.testString ?? "" }, + objects.map { $0.testString ?? "" }, [ "nil:TestEntity1:2", "nil:TestEntity1:1" ] ) - let objectIDs = transaction.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 2) + let objectIDs = try transaction.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 2) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -2885,13 +2773,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let objects = transaction.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 0) + let objects = try transaction.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 0) - let objectIDs = transaction.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 0) + let objectIDs = try transaction.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 0) } try transaction.cancel() } @@ -2907,22 +2793,20 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = transaction.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 2) + let objects = try transaction.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 2) XCTAssertEqual( - (objects ?? []).map { $0.testString ?? "" }, + objects.map { $0.testString ?? "" }, [ "Config1:TestEntity1:4", "Config1:TestEntity1:5" ] ) - let objectIDs = transaction.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 2) + let objectIDs = try transaction.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 2) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -2932,22 +2816,20 @@ final class FetchTests: BaseTestDataTestCase { OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ] - let objects = transaction.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 2) + let objects = try transaction.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 2) XCTAssertEqual( - (objects ?? []).map { $0.testString ?? "" }, + objects.map { $0.testString ?? "" }, [ "Config1:TestEntity1:2", "Config1:TestEntity1:1" ] ) - let objectIDs = transaction.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 2) + let objectIDs = try transaction.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 2) XCTAssertEqual( - (objectIDs ?? []), - (objects ?? []).map { $0.objectID } + objectIDs, + objects.map { $0.objectID } ) } do { @@ -2956,13 +2838,11 @@ final class FetchTests: BaseTestDataTestCase { Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ] - let objects = transaction.fetchAll(from, fetchClauses) - XCTAssertNotNil(objects) - XCTAssertEqual(objects?.count, 0) + let objects = try transaction.fetchAll(from, fetchClauses) + XCTAssertEqual(objects.count, 0) - let objectIDs = transaction.fetchObjectIDs(from, fetchClauses) - XCTAssertNotNil(objectIDs) - XCTAssertEqual(objectIDs?.count, 0) + let objectIDs = try transaction.fetchObjectIDs(from, fetchClauses) + XCTAssertEqual(objectIDs.count, 0) } try transaction.cancel() } @@ -2983,7 +2863,7 @@ final class FetchTests: BaseTestDataTestCase { let from = From() do { - let count = transaction.fetchCount( + let count = try transaction.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), @@ -2994,7 +2874,7 @@ final class FetchTests: BaseTestDataTestCase { } do { - let count = transaction.fetchCount( + let count = try transaction.fetchCount( from, Where("%K < %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), @@ -3005,7 +2885,7 @@ final class FetchTests: BaseTestDataTestCase { } do { - let count = transaction.fetchCount( + let count = try transaction.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) @@ -3022,7 +2902,7 @@ final class FetchTests: BaseTestDataTestCase { let from = From(nil) do { - let count = transaction.fetchCount( + let count = try transaction.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 1), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), @@ -3033,7 +2913,7 @@ final class FetchTests: BaseTestDataTestCase { } do { - let count = transaction.fetchCount( + let count = try transaction.fetchCount( from, Where("%K < %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), @@ -3044,7 +2924,7 @@ final class FetchTests: BaseTestDataTestCase { } do { - let count = transaction.fetchCount( + let count = try transaction.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) @@ -3061,9 +2941,9 @@ final class FetchTests: BaseTestDataTestCase { let from = From("Config1") do { - let count = self.expectLogger([.logWarning]) { + let count = try? self.expectLogger([.logError]) { - transaction.fetchCount( + try transaction.fetchCount( from, Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) @@ -3073,9 +2953,9 @@ final class FetchTests: BaseTestDataTestCase { } do { - let count = self.expectLogger([.logWarning]) { + let count = try? self.expectLogger([.logError]) { - transaction.fetchCount( + try transaction.fetchCount( from, Where(#keyPath(TestEntity1.testNumber), isEqualTo: 0), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) @@ -3085,9 +2965,9 @@ final class FetchTests: BaseTestDataTestCase { } do { - let count = self.expectLogger([.logWarning]) { + let count = try? self.expectLogger([.logError]) { - transaction.fetchCount( + try transaction.fetchCount( from, Where(#keyPath(TestEntity1.testNumber), isEqualTo: nil), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) @@ -3114,34 +2994,31 @@ final class FetchTests: BaseTestDataTestCase { let from = From() do { - let count = transaction.fetchCount( + let count = try transaction.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 3) } do { - let count = transaction.fetchCount( + let count = try transaction.fetchCount( from, Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 3) } do { - let count = transaction.fetchCount( + let count = try transaction.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) - XCTAssertNotNil(count) XCTAssertEqual(count, 0) } try transaction.cancel() @@ -3153,34 +3030,31 @@ final class FetchTests: BaseTestDataTestCase { let from = From(nil) do { - let count = transaction.fetchCount( + let count = try transaction.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 2) } do { - let count = transaction.fetchCount( + let count = try transaction.fetchCount( from, Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 2) } do { - let count = transaction.fetchCount( + let count = try transaction.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) - XCTAssertNotNil(count) XCTAssertEqual(count, 0) } try transaction.cancel() @@ -3192,34 +3066,31 @@ final class FetchTests: BaseTestDataTestCase { let from = From("Config1") do { - let count = transaction.fetchCount( + let count = try transaction.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 2) } do { - let count = transaction.fetchCount( + let count = try transaction.fetchCount( from, Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 2) } do { - let count = transaction.fetchCount( + let count = try transaction.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) - XCTAssertNotNil(count) XCTAssertEqual(count, 0) } try transaction.cancel() @@ -3231,9 +3102,9 @@ final class FetchTests: BaseTestDataTestCase { let from = From("Config2") do { - let count = self.expectLogger([.logWarning]) { + let count = try? self.expectLogger([.logError]) { - transaction.fetchCount( + try transaction.fetchCount( from, Where("%K < %@", #keyPath(TestEntity1.testNumber), 4), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) @@ -3243,9 +3114,9 @@ final class FetchTests: BaseTestDataTestCase { } do { - let count = self.expectLogger([.logWarning]) { + let count = try? self.expectLogger([.logError]) { - transaction.fetchCount( + try transaction.fetchCount( from, Where(#keyPath(TestEntity1.testNumber), isEqualTo: 0), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) @@ -3255,9 +3126,9 @@ final class FetchTests: BaseTestDataTestCase { } do { - let count = self.expectLogger([.logWarning]) { + let count = try? self.expectLogger([.logError]) { - transaction.fetchCount( + try transaction.fetchCount( from, Where(#keyPath(TestEntity1.testNumber), isEqualTo: nil), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))) @@ -3284,34 +3155,31 @@ final class FetchTests: BaseTestDataTestCase { let from = From(nil, "Config1") do { - let count = transaction.fetchCount( + let count = try transaction.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 3) } do { - let count = transaction.fetchCount( + let count = try transaction.fetchCount( from, Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 3) } do { - let count = transaction.fetchCount( + let count = try transaction.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) - XCTAssertNotNil(count) XCTAssertEqual(count, 0) } try transaction.cancel() @@ -3323,34 +3191,31 @@ final class FetchTests: BaseTestDataTestCase { let from = From(nil, "Config2") do { - let count = transaction.fetchCount( + let count = try transaction.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 2) } do { - let count = transaction.fetchCount( + let count = try transaction.fetchCount( from, Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 2) } do { - let count = transaction.fetchCount( + let count = try transaction.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) - XCTAssertNotNil(count) XCTAssertEqual(count, 0) } try transaction.cancel() @@ -3362,34 +3227,31 @@ final class FetchTests: BaseTestDataTestCase { let from = From("Config1", "Config2") do { - let count = transaction.fetchCount( + let count = try transaction.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 3), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 2) } do { - let count = transaction.fetchCount( + let count = try transaction.fetchCount( from, Where("%K < %@", #keyPath(TestEntity1.testNumber), 3), OrderBy(.descending(#keyPath(TestEntity1.testEntityID))), Tweak { $0.fetchLimit = 3 } ) - XCTAssertNotNil(count) XCTAssertEqual(count, 2) } do { - let count = transaction.fetchCount( + let count = try transaction.fetchCount( from, Where("%K > %@", #keyPath(TestEntity1.testNumber), 5), OrderBy(.ascending(#keyPath(TestEntity1.testEntityID))) ) - XCTAssertNotNil(count) XCTAssertEqual(count, 0) } try transaction.cancel() diff --git a/CoreStoreTests/FromTests.swift b/CoreStoreTests/FromTests.swift index 88477be..2be6e4a 100644 --- a/CoreStoreTests/FromTests.swift +++ b/CoreStoreTests/FromTests.swift @@ -75,8 +75,7 @@ final class FromTests: BaseTestCase { let from = From() let request = CoreStoreFetchRequest() - let storesFound = from.applyToFetchRequest(request, context: dataStack.mainContext) - XCTAssertTrue(storesFound) + try from.applyToFetchRequest(request, context: dataStack.mainContext) XCTAssertNotNil(request.entity) XCTAssertNotNil(request.safeAffectedStores) @@ -90,11 +89,11 @@ final class FromTests: BaseTestCase { let from = From("Config1") let request = CoreStoreFetchRequest() - let storesFound = self.expectLogger([.logWarning]) { + let storesFound: Void? = try? self.expectLogger([.logError]) { - from.applyToFetchRequest(request, context: dataStack.mainContext) + try from.applyToFetchRequest(request, context: dataStack.mainContext) } - XCTAssertFalse(storesFound) + XCTAssertNil(storesFound) XCTAssertNotNil(request.entity) XCTAssertNotNil(request.safeAffectedStores) @@ -116,8 +115,8 @@ final class FromTests: BaseTestCase { let from = From() let request = CoreStoreFetchRequest() - let storesFound = from.applyToFetchRequest(request, context: dataStack.mainContext) - XCTAssertTrue(storesFound) + let storesFound: Void? = try? from.applyToFetchRequest(request, context: dataStack.mainContext) + XCTAssertNotNil(storesFound) XCTAssertNotNil(request.entity) XCTAssertNotNil(request.safeAffectedStores) @@ -131,8 +130,8 @@ final class FromTests: BaseTestCase { let from = From("Config1") let request = CoreStoreFetchRequest() - let storesFound = from.applyToFetchRequest(request, context: dataStack.mainContext) - XCTAssertTrue(storesFound) + let storesFound: Void? = try? from.applyToFetchRequest(request, context: dataStack.mainContext) + XCTAssertNotNil(storesFound) XCTAssertNotNil(request.entity) XCTAssertNotNil(request.safeAffectedStores) @@ -146,11 +145,11 @@ final class FromTests: BaseTestCase { let from = From("Config2") let request = CoreStoreFetchRequest() - let storesFound = self.expectLogger([.logWarning]) { + let storesFound: Void? = try? self.expectLogger([.logError]) { - from.applyToFetchRequest(request, context: dataStack.mainContext) + try from.applyToFetchRequest(request, context: dataStack.mainContext) } - XCTAssertFalse(storesFound) + XCTAssertNil(storesFound) XCTAssertNotNil(request.entity) XCTAssertNotNil(request.safeAffectedStores) @@ -164,11 +163,11 @@ final class FromTests: BaseTestCase { let from = From() let request = CoreStoreFetchRequest() - let storesFound = self.expectLogger([.logWarning]) { + let storesFound: Void? = try? self.expectLogger([.logError]) { - from.applyToFetchRequest(request, context: dataStack.mainContext) + try from.applyToFetchRequest(request, context: dataStack.mainContext) } - XCTAssertFalse(storesFound) + XCTAssertNil(storesFound) XCTAssertNotNil(request.entity) XCTAssertNotNil(request.safeAffectedStores) @@ -182,11 +181,11 @@ final class FromTests: BaseTestCase { let from = From("Config1") let request = CoreStoreFetchRequest() - let storesFound = self.expectLogger([.logWarning]) { + let storesFound: Void? = try? self.expectLogger([.logError]) { - from.applyToFetchRequest(request, context: dataStack.mainContext) + try from.applyToFetchRequest(request, context: dataStack.mainContext) } - XCTAssertFalse(storesFound) + XCTAssertNil(storesFound) XCTAssertNotNil(request.entity) XCTAssertNotNil(request.safeAffectedStores) @@ -200,11 +199,11 @@ final class FromTests: BaseTestCase { let from = From("Config2") let request = CoreStoreFetchRequest() - let storesFound = self.expectLogger([.logWarning]) { + let storesFound: Void? = try? self.expectLogger([.logError]) { - from.applyToFetchRequest(request, context: dataStack.mainContext) + try from.applyToFetchRequest(request, context: dataStack.mainContext) } - XCTAssertFalse(storesFound) + XCTAssertNil(storesFound) XCTAssertNotNil(request.entity) XCTAssertNotNil(request.safeAffectedStores) @@ -226,8 +225,8 @@ final class FromTests: BaseTestCase { let from = From() let request = CoreStoreFetchRequest() - let storesFound = from.applyToFetchRequest(request, context: dataStack.mainContext) - XCTAssertTrue(storesFound) + let storesFound: Void? = try? from.applyToFetchRequest(request, context: dataStack.mainContext) + XCTAssertNotNil(storesFound) XCTAssertNotNil(request.entity) XCTAssertNotNil(request.safeAffectedStores) @@ -241,8 +240,8 @@ final class FromTests: BaseTestCase { let from = From("Config1") let request = CoreStoreFetchRequest() - let storesFound = from.applyToFetchRequest(request, context: dataStack.mainContext) - XCTAssertTrue(storesFound) + let storesFound: Void? = try? from.applyToFetchRequest(request, context: dataStack.mainContext) + XCTAssertNotNil(storesFound) XCTAssertNotNil(request.entity) XCTAssertNotNil(request.safeAffectedStores) @@ -256,11 +255,11 @@ final class FromTests: BaseTestCase { let from = From("Config2") let request = CoreStoreFetchRequest() - let storesFound = self.expectLogger([.logWarning]) { + let storesFound: Void? = try? self.expectLogger([.logError]) { - from.applyToFetchRequest(request, context: dataStack.mainContext) + try from.applyToFetchRequest(request, context: dataStack.mainContext) } - XCTAssertFalse(storesFound) + XCTAssertNil(storesFound) XCTAssertNotNil(request.entity) XCTAssertNotNil(request.safeAffectedStores) @@ -274,8 +273,8 @@ final class FromTests: BaseTestCase { let from = From() let request = CoreStoreFetchRequest() - let storesFound = from.applyToFetchRequest(request, context: dataStack.mainContext) - XCTAssertTrue(storesFound) + let storesFound: Void? = try? from.applyToFetchRequest(request, context: dataStack.mainContext) + XCTAssertNotNil(storesFound) XCTAssertNotNil(request.entity) XCTAssertNotNil(request.safeAffectedStores) @@ -289,11 +288,11 @@ final class FromTests: BaseTestCase { let from = From("Config1") let request = CoreStoreFetchRequest() - let storesFound = self.expectLogger([.logWarning]) { + let storesFound: Void? = try? self.expectLogger([.logError]) { - from.applyToFetchRequest(request, context: dataStack.mainContext) + try from.applyToFetchRequest(request, context: dataStack.mainContext) } - XCTAssertFalse(storesFound) + XCTAssertNil(storesFound) XCTAssertNotNil(request.entity) XCTAssertNotNil(request.safeAffectedStores) @@ -307,11 +306,11 @@ final class FromTests: BaseTestCase { let from = From("Config2") let request = CoreStoreFetchRequest() - let storesFound = self.expectLogger([.logWarning]) { + let storesFound: Void? = try? self.expectLogger([.logError]) { - from.applyToFetchRequest(request, context: dataStack.mainContext) + try from.applyToFetchRequest(request, context: dataStack.mainContext) } - XCTAssertFalse(storesFound) + XCTAssertNil(storesFound) XCTAssertNotNil(request.entity) XCTAssertNotNil(request.safeAffectedStores) @@ -333,8 +332,8 @@ final class FromTests: BaseTestCase { let from = From() let request = CoreStoreFetchRequest() - let storesFound = from.applyToFetchRequest(request, context: dataStack.mainContext) - XCTAssertTrue(storesFound) + let storesFound: Void? = try? from.applyToFetchRequest(request, context: dataStack.mainContext) + XCTAssertNotNil(storesFound) XCTAssertNotNil(request.entity) XCTAssertNotNil(request.safeAffectedStores) @@ -348,8 +347,8 @@ final class FromTests: BaseTestCase { let from = From("Config1") let request = CoreStoreFetchRequest() - let storesFound = from.applyToFetchRequest(request, context: dataStack.mainContext) - XCTAssertTrue(storesFound) + let storesFound: Void? = try? from.applyToFetchRequest(request, context: dataStack.mainContext) + XCTAssertNotNil(storesFound) XCTAssertNotNil(request.entity) XCTAssertNotNil(request.safeAffectedStores) @@ -363,11 +362,11 @@ final class FromTests: BaseTestCase { let from = From("Config2") let request = CoreStoreFetchRequest() - let storesFound = self.expectLogger([.logWarning]) { + let storesFound: Void? = try? self.expectLogger([.logError]) { - from.applyToFetchRequest(request, context: dataStack.mainContext) + try from.applyToFetchRequest(request, context: dataStack.mainContext) } - XCTAssertFalse(storesFound) + XCTAssertNil(storesFound) XCTAssertNotNil(request.entity) XCTAssertNotNil(request.safeAffectedStores) @@ -381,8 +380,8 @@ final class FromTests: BaseTestCase { let from = From() let request = CoreStoreFetchRequest() - let storesFound = from.applyToFetchRequest(request, context: dataStack.mainContext) - XCTAssertTrue(storesFound) + let storesFound: Void? = try? from.applyToFetchRequest(request, context: dataStack.mainContext) + XCTAssertNotNil(storesFound) XCTAssertNotNil(request.entity) XCTAssertNotNil(request.safeAffectedStores) @@ -396,11 +395,11 @@ final class FromTests: BaseTestCase { let from = From("Config1") let request = CoreStoreFetchRequest() - let storesFound = self.expectLogger([.logWarning]) { + let storesFound: Void? = try? self.expectLogger([.logError]) { - from.applyToFetchRequest(request, context: dataStack.mainContext) + try from.applyToFetchRequest(request, context: dataStack.mainContext) } - XCTAssertFalse(storesFound) + XCTAssertNil(storesFound) XCTAssertNotNil(request.entity) XCTAssertNotNil(request.safeAffectedStores) @@ -414,8 +413,8 @@ final class FromTests: BaseTestCase { let from = From("Config2") let request = CoreStoreFetchRequest() - let storesFound = from.applyToFetchRequest(request, context: dataStack.mainContext) - XCTAssertTrue(storesFound) + let storesFound: Void? = try? from.applyToFetchRequest(request, context: dataStack.mainContext) + XCTAssertNotNil(storesFound) XCTAssertNotNil(request.entity) XCTAssertNotNil(request.safeAffectedStores) diff --git a/CoreStoreTests/GroupByTests.swift b/CoreStoreTests/GroupByTests.swift index 7735181..a209566 100644 --- a/CoreStoreTests/GroupByTests.swift +++ b/CoreStoreTests/GroupByTests.swift @@ -69,7 +69,7 @@ final class GroupByTests: BaseTestCase { let groupBy = GroupBy(#keyPath(TestEntity1.testString)) let request = CoreStoreFetchRequest() - _ = From().applyToFetchRequest(request, context: dataStack.mainContext) + try From().applyToFetchRequest(request, context: dataStack.mainContext) groupBy.applyToFetchRequest(request) XCTAssertNotNil(request.propertiesToGroupBy) diff --git a/CoreStoreTests/ImportTests.swift b/CoreStoreTests/ImportTests.swift index 3b414e6..3111c67 100644 --- a/CoreStoreTests/ImportTests.swift +++ b/CoreStoreTests/ImportTests.swift @@ -95,7 +95,7 @@ class ImportTests: BaseTestDataTestCase { ] ) XCTAssertNil(object) - XCTAssertEqual(transaction.fetchCount(From()), 0) + XCTAssertEqual(try transaction.fetchCount(From()), 0) } ) } @@ -103,7 +103,7 @@ class ImportTests: BaseTestDataTestCase { XCTFail() } - XCTAssertEqual(stack.fetchCount(From()), 0) + XCTAssertEqual(try stack.fetchCount(From()), 0) } } @@ -137,9 +137,9 @@ class ImportTests: BaseTestDataTestCase { catch _ as TestInsertError { errorExpectation.fulfill() - XCTAssertEqual(transaction.fetchCount(From()), 1) + XCTAssertEqual(try transaction.fetchCount(From()), 1) - let object = transaction.fetchOne(From()) + let object = try transaction.fetchOne(From()) XCTAssertNotNil(object) XCTAssertNil(object?.testEntityID) XCTAssertNil(object?.testBoolean) @@ -182,7 +182,7 @@ class ImportTests: BaseTestDataTestCase { ] ) XCTAssertNotNil(object) - XCTAssertEqual(transaction.fetchCount(From()), 1) + XCTAssertEqual(try transaction.fetchCount(From()), 1) XCTAssertNil(object?.testEntityID) XCTAssertEqual(object?.testBoolean, NSNumber(value: true)) XCTAssertEqual(object?.testNumber, NSNumber(value: 1)) @@ -202,7 +202,7 @@ class ImportTests: BaseTestDataTestCase { #keyPath(TestEntity1.testDate): self.dateFormatter.date(from: "2000-01-02T00:00:00Z")! ] ) - XCTAssertEqual(transaction.fetchCount(From()), 1) + XCTAssertEqual(try transaction.fetchCount(From()), 1) XCTAssertNil(object?.testEntityID) XCTAssertEqual(object?.testBoolean, NSNumber(value: false)) XCTAssertEqual(object?.testNumber, NSNumber(value: 2)) @@ -254,7 +254,7 @@ class ImportTests: BaseTestDataTestCase { sourceArray: sourceArray ) XCTAssertEqual(objects.count, 1) - XCTAssertEqual(transaction.fetchCount(From()), 1) + XCTAssertEqual(try transaction.fetchCount(From()), 1) let object = objects[0] let dictionary = sourceArray[1] @@ -316,9 +316,9 @@ class ImportTests: BaseTestDataTestCase { catch _ as TestInsertError { errorExpectation.fulfill() - XCTAssertEqual(transaction.fetchCount(From()), 1) + XCTAssertEqual(try transaction.fetchCount(From()), 1) - let object = transaction.fetchOne(From()) + let object = try transaction.fetchOne(From()) XCTAssertNotNil(object) XCTAssertNil(object?.testEntityID) XCTAssertNil(object?.testBoolean) @@ -372,7 +372,7 @@ class ImportTests: BaseTestDataTestCase { sourceArray: sourceArray ) XCTAssertEqual(objects.count, sourceArray.count) - XCTAssertEqual(transaction.fetchCount(From()), 2) + XCTAssertEqual(try transaction.fetchCount(From()), 2) for i in 0 ..< sourceArray.count { @@ -424,7 +424,7 @@ class ImportTests: BaseTestDataTestCase { ] ) XCTAssertNil(object) - XCTAssertEqual(transaction.fetchCount(From()), 5) + XCTAssertEqual(try transaction.fetchCount(From()), 5) } do { @@ -442,20 +442,19 @@ class ImportTests: BaseTestDataTestCase { ] ) XCTAssertNil(object) - XCTAssertEqual(transaction.fetchCount(From()), 5) + XCTAssertEqual(try transaction.fetchCount(From()), 5) - let existingObjects = transaction.fetchAll(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105)) - XCTAssertNotNil(existingObjects) - XCTAssertEqual(existingObjects?.count, 1) + let existingObjects = try transaction.fetchAll(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105)) + XCTAssertEqual(existingObjects.count, 1) - let existingObject = existingObjects?[0] - XCTAssertEqual(existingObject?.testEntityID, NSNumber(value: 105)) - XCTAssertEqual(existingObject?.testBoolean, NSNumber(value: true)) - XCTAssertEqual(existingObject?.testNumber, NSNumber(value: 5)) - XCTAssertEqual(existingObject?.testDecimal, NSDecimalNumber(string: "5")) - XCTAssertEqual(existingObject?.testString, "nil:TestEntity1:5") - XCTAssertEqual(existingObject?.testData, ("nil:TestEntity1:5" as NSString).data(using: String.Encoding.utf8.rawValue)!) - XCTAssertEqual(existingObject?.testDate, self.dateFormatter.date(from: "2000-01-05T00:00:00Z")!) + let existingObject = existingObjects[0] + XCTAssertEqual(existingObject.testEntityID, NSNumber(value: 105)) + XCTAssertEqual(existingObject.testBoolean, NSNumber(value: true)) + XCTAssertEqual(existingObject.testNumber, NSNumber(value: 5)) + XCTAssertEqual(existingObject.testDecimal, NSDecimalNumber(string: "5")) + XCTAssertEqual(existingObject.testString, "nil:TestEntity1:5") + XCTAssertEqual(existingObject.testData, ("nil:TestEntity1:5" as NSString).data(using: String.Encoding.utf8.rawValue)!) + XCTAssertEqual(existingObject.testDate, self.dateFormatter.date(from: "2000-01-05T00:00:00Z")!) } } ) @@ -504,7 +503,7 @@ class ImportTests: BaseTestDataTestCase { ) XCTAssertEqual(objects.count, 1) - XCTAssertEqual(transaction.fetchCount(From()), 6) + XCTAssertEqual(try transaction.fetchCount(From()), 6) let object = objects[0] let dictionary = sourceArray[1] @@ -618,9 +617,9 @@ class ImportTests: BaseTestDataTestCase { catch _ as TestInsertError { errorExpectation.fulfill() - XCTAssertEqual(transaction.fetchCount(From()), 6) + XCTAssertEqual(try transaction.fetchCount(From()), 6) - let object = transaction.fetchOne(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 106)) + let object = try transaction.fetchOne(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 106)) XCTAssertNotNil(object) XCTAssertEqual(object?.testEntityID, NSNumber(value: 106)) XCTAssertNil(object?.testBoolean) @@ -657,21 +656,19 @@ class ImportTests: BaseTestDataTestCase { catch _ as TestUpdateError { errorExpectation.fulfill() - XCTAssertEqual(transaction.fetchCount(From()), 6) + XCTAssertEqual(try transaction.fetchCount(From()), 6) - let existingObjects = transaction.fetchAll(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105)) - XCTAssertNotNil(existingObjects) - XCTAssertEqual(existingObjects?.count, 1) + let existingObjects = try transaction.fetchAll(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105)) + XCTAssertEqual(existingObjects.count, 1) - let existingObject = existingObjects?[0] - XCTAssertNotNil(existingObject) - XCTAssertEqual(existingObject?.testEntityID, NSNumber(value: 105)) - XCTAssertEqual(existingObject?.testBoolean, NSNumber(value: true)) - XCTAssertEqual(existingObject?.testNumber, NSNumber(value: 5)) - XCTAssertEqual(existingObject?.testDecimal, NSDecimalNumber(string: "5")) - XCTAssertEqual(existingObject?.testString, "nil:TestEntity1:5") - XCTAssertEqual(existingObject?.testData, ("nil:TestEntity1:5" as NSString).data(using: String.Encoding.utf8.rawValue)!) - XCTAssertEqual(existingObject?.testDate, self.dateFormatter.date(from: "2000-01-05T00:00:00Z")!) + let existingObject = existingObjects[0] + XCTAssertEqual(existingObject.testEntityID, NSNumber(value: 105)) + XCTAssertEqual(existingObject.testBoolean, NSNumber(value: true)) + XCTAssertEqual(existingObject.testNumber, NSNumber(value: 5)) + XCTAssertEqual(existingObject.testDecimal, NSDecimalNumber(string: "5")) + XCTAssertEqual(existingObject.testString, "nil:TestEntity1:5") + XCTAssertEqual(existingObject.testData, ("nil:TestEntity1:5" as NSString).data(using: String.Encoding.utf8.rawValue)!) + XCTAssertEqual(existingObject.testDate, self.dateFormatter.date(from: "2000-01-05T00:00:00Z")!) } self.checkExpectationsImmediately() } @@ -710,7 +707,7 @@ class ImportTests: BaseTestDataTestCase { ] ) XCTAssertNotNil(object) - XCTAssertEqual(transaction.fetchCount(From()), 6) + XCTAssertEqual(try transaction.fetchCount(From()), 6) XCTAssertEqual(object?.testEntityID, NSNumber(value: 106)) XCTAssertEqual(object?.testBoolean, NSNumber(value: true)) @@ -735,7 +732,7 @@ class ImportTests: BaseTestDataTestCase { ] ) XCTAssertNotNil(object) - XCTAssertEqual(transaction.fetchCount(From()), 6) + XCTAssertEqual(try transaction.fetchCount(From()), 6) XCTAssertEqual(object?.testEntityID, NSNumber(value: 106)) XCTAssertEqual(object?.testBoolean, NSNumber(value: false)) @@ -745,11 +742,10 @@ class ImportTests: BaseTestDataTestCase { XCTAssertEqual(object?.testData, ("nil:TestEntity1:7" as NSString).data(using: String.Encoding.utf8.rawValue)!) XCTAssertEqual(object?.testDate, self.dateFormatter.date(from: "2000-01-07T00:00:00Z")!) - let existingObjects = transaction.fetchAll(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 106)) - XCTAssertNotNil(existingObjects) - XCTAssertEqual(existingObjects?.count, 1) + let existingObjects = try transaction.fetchAll(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 106)) + XCTAssertEqual(existingObjects.count, 1) - let existingObject = existingObjects?[0] + let existingObject = existingObjects[0] XCTAssertEqual(existingObject, object) } } @@ -799,7 +795,7 @@ class ImportTests: BaseTestDataTestCase { sourceArray: sourceArray ) XCTAssertEqual(objects.count, 1) - XCTAssertEqual(transaction.fetchCount(From()), 6) + XCTAssertEqual(try transaction.fetchCount(From()), 6) let object = objects[0] let dictionary = sourceArray[1] @@ -864,10 +860,10 @@ class ImportTests: BaseTestDataTestCase { catch _ as TestIDError { errorExpectation.fulfill() - XCTAssertEqual(transaction.fetchCount(From()), 5) + XCTAssertEqual(try transaction.fetchCount(From()), 5) - XCTAssertNil(transaction.fetchOne(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 106))) - XCTAssertNil(transaction.fetchOne(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 107))) + XCTAssertNil(try transaction.fetchOne(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 106))) + XCTAssertNil(try transaction.fetchOne(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 107))) } transaction.unsafeContext().reset() self.checkExpectationsImmediately() @@ -910,7 +906,7 @@ class ImportTests: BaseTestDataTestCase { errorExpectation.fulfill() - let object = transaction.fetchOne(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 106)) + let object = try transaction.fetchOne(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 106)) XCTAssertNotNil(object) XCTAssertEqual(object?.testEntityID, NSNumber(value: 106)) XCTAssertNil(object?.testBoolean) @@ -951,9 +947,9 @@ class ImportTests: BaseTestDataTestCase { catch _ as TestUpdateError { errorExpectation.fulfill() - XCTAssertEqual(transaction.fetchCount(From()), 5) + XCTAssertEqual(try transaction.fetchCount(From()), 5) - let object = transaction.fetchOne(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105)) + let object = try transaction.fetchOne(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105)) XCTAssertNotNil(object) XCTAssertEqual(object?.testEntityID, NSNumber(value: 105)) XCTAssertEqual(object?.testBoolean, NSNumber(value: true)) @@ -963,11 +959,10 @@ class ImportTests: BaseTestDataTestCase { XCTAssertEqual(object?.testData, ("nil:TestEntity1:5" as NSString).data(using: String.Encoding.utf8.rawValue)!) XCTAssertEqual(object?.testDate, self.dateFormatter.date(from: "2000-01-05T00:00:00Z")!) - let existingObjects = transaction.fetchAll(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105)) - XCTAssertNotNil(existingObjects) - XCTAssertEqual(existingObjects?.count, 1) + let existingObjects = try transaction.fetchAll(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105)) + XCTAssertEqual(existingObjects.count, 1) - let existingObject = existingObjects?[0] + let existingObject = existingObjects[0] XCTAssertEqual(existingObject, object) } transaction.context.reset() @@ -1018,7 +1013,7 @@ class ImportTests: BaseTestDataTestCase { sourceArray: sourceArray ) XCTAssertEqual(objects.count, sourceArray.count) - XCTAssertEqual(transaction.fetchCount(From()), 6) + XCTAssertEqual(try transaction.fetchCount(From()), 6) for i in 0 ..< sourceArray.count { let object = objects[i] @@ -1032,11 +1027,10 @@ class ImportTests: BaseTestDataTestCase { XCTAssertEqual(object.testData, dictionary[(#keyPath(TestEntity1.testData))] as? Data) XCTAssertEqual(object.testDate, dictionary[(#keyPath(TestEntity1.testDate))] as? Date) } - let existingObjects = transaction.fetchAll(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105)) - XCTAssertNotNil(existingObjects) - XCTAssertEqual(existingObjects?.count, 1) + let existingObjects = try transaction.fetchAll(From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 105)) + XCTAssertEqual(existingObjects.count, 1) - let existingObject = existingObjects?[0] + let existingObject = existingObjects[0] XCTAssertEqual(existingObject, objects[0]) } ) diff --git a/CoreStoreTests/ListObserverTests.swift b/CoreStoreTests/ListObserverTests.swift index b89d4a7..7257df9 100644 --- a/CoreStoreTests/ListObserverTests.swift +++ b/CoreStoreTests/ListObserverTests.swift @@ -76,7 +76,7 @@ class ListObserverTests: BaseTestDataTestCase { XCTAssertEqual( ((note.userInfo as NSDictionary?) ?? [:]), [ - "sectionInfo": monitor.sectionInfoAtIndex(0), + "sectionInfo": monitor.sectionInfo(at: 0), "sectionIndex": 0 ] as NSDictionary ) @@ -178,9 +178,9 @@ class ListObserverTests: BaseTestDataTestCase { XCTAssertTrue(monitor.hasSections()) XCTAssertEqual(monitor.numberOfSections(), 2) XCTAssertTrue(monitor.hasObjects()) - XCTAssertTrue(monitor.hasObjectsInSection(0)) - XCTAssertEqual(monitor.numberOfObjectsInSection(0), 2) - XCTAssertEqual(monitor.numberOfObjectsInSection(1), 3) + XCTAssertTrue(monitor.hasObjects(in: 0)) + XCTAssertEqual(monitor.numberOfObjects(in: 0), 2) + XCTAssertEqual(monitor.numberOfObjects(in: 1), 3) var events = 0 @@ -268,7 +268,7 @@ class ListObserverTests: BaseTestDataTestCase { stack.perform( asynchronous: { (transaction) -> Bool in - if let object = transaction.fetchOne( + if let object = try transaction.fetchOne( From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 101)) { @@ -282,7 +282,7 @@ class ListObserverTests: BaseTestDataTestCase { XCTFail() } - if let object = transaction.fetchOne( + if let object = try transaction.fetchOne( From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 102)) { @@ -394,7 +394,7 @@ class ListObserverTests: BaseTestDataTestCase { stack.perform( asynchronous: { (transaction) -> Bool in - if let object = transaction.fetchOne( + if let object = try transaction.fetchOne( From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 102)) { @@ -526,7 +526,7 @@ class ListObserverTests: BaseTestDataTestCase { stack.perform( asynchronous: { (transaction) -> Bool in - let count = transaction.deleteAll( + let count = try transaction.deleteAll( From(), Where(#keyPath(TestEntity1.testBoolean), isEqualTo: false) ) diff --git a/CoreStoreTests/ObjectObserverTests.swift b/CoreStoreTests/ObjectObserverTests.swift index 95a53e4..df92521 100644 --- a/CoreStoreTests/ObjectObserverTests.swift +++ b/CoreStoreTests/ObjectObserverTests.swift @@ -41,7 +41,7 @@ class ObjectObserverTests: BaseTestDataTestCase { self.prepareTestDataForStack(stack) - guard let object = stack.fetchOne( + guard let object = try stack.fetchOne( From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 101)) else { @@ -138,7 +138,7 @@ class ObjectObserverTests: BaseTestDataTestCase { self.prepareTestDataForStack(stack) - guard let object = stack.fetchOne( + guard let object = try stack.fetchOne( From(), Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 101)) else { diff --git a/CoreStoreTests/QueryTests.swift b/CoreStoreTests/QueryTests.swift index 3e6fc07..8ce9b21 100644 --- a/CoreStoreTests/QueryTests.swift +++ b/CoreStoreTests/QueryTests.swift @@ -47,7 +47,7 @@ class QueryTests: BaseTestDataTestCase { ] do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(#keyPath(TestEntity1.testBoolean)), queryClauses @@ -57,7 +57,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(#keyPath(TestEntity1.testNumber)), queryClauses @@ -67,7 +67,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(#keyPath(TestEntity1.testNumber)), queryClauses @@ -77,7 +77,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(#keyPath(TestEntity1.testNumber)), queryClauses @@ -87,7 +87,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(#keyPath(TestEntity1.testNumber)), queryClauses @@ -97,7 +97,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(#keyPath(TestEntity1.testNumber)), queryClauses @@ -107,7 +107,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(#keyPath(TestEntity1.testNumber)), queryClauses @@ -117,7 +117,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(#keyPath(TestEntity1.testNumber)), queryClauses @@ -127,7 +127,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(#keyPath(TestEntity1.testNumber)), queryClauses @@ -137,7 +137,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(#keyPath(TestEntity1.testDecimal)), queryClauses @@ -147,7 +147,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(#keyPath(TestEntity1.testString)), queryClauses @@ -157,7 +157,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(#keyPath(TestEntity1.testString)), queryClauses @@ -167,7 +167,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(#keyPath(TestEntity1.testData)), queryClauses @@ -177,7 +177,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(#keyPath(TestEntity1.testData)), queryClauses @@ -187,7 +187,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(#keyPath(TestEntity1.testDate)), queryClauses @@ -197,7 +197,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(#keyPath(TestEntity1.testDate)), queryClauses @@ -207,7 +207,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(#keyPath(TestEntity1.testDate)), queryClauses @@ -232,7 +232,7 @@ class QueryTests: BaseTestDataTestCase { ] do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.average(#keyPath(TestEntity1.testBoolean))), queryClauses @@ -242,7 +242,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.average(#keyPath(TestEntity1.testNumber))), queryClauses @@ -252,7 +252,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.average(#keyPath(TestEntity1.testNumber))), queryClauses @@ -262,7 +262,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.average(#keyPath(TestEntity1.testNumber))), queryClauses @@ -272,7 +272,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.average(#keyPath(TestEntity1.testNumber))), queryClauses @@ -282,7 +282,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.average(#keyPath(TestEntity1.testNumber))), queryClauses @@ -292,7 +292,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.average(#keyPath(TestEntity1.testNumber))), queryClauses @@ -302,7 +302,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.average(#keyPath(TestEntity1.testNumber))), queryClauses @@ -312,7 +312,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.average(#keyPath(TestEntity1.testNumber))), queryClauses @@ -322,7 +322,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.average(#keyPath(TestEntity1.testDecimal))), queryClauses @@ -332,7 +332,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.average(#keyPath(TestEntity1.testString))), queryClauses @@ -341,7 +341,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.average(#keyPath(TestEntity1.testString))), queryClauses @@ -350,7 +350,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.average(#keyPath(TestEntity1.testData))), queryClauses @@ -359,7 +359,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.average(#keyPath(TestEntity1.testData))), queryClauses @@ -368,7 +368,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.average(#keyPath(TestEntity1.testDate))), queryClauses @@ -377,7 +377,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.average(#keyPath(TestEntity1.testDate))), queryClauses @@ -386,7 +386,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(#keyPath(TestEntity1.testEntityID)), queryClauses @@ -410,7 +410,7 @@ class QueryTests: BaseTestDataTestCase { ] do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.count(#keyPath(TestEntity1.testBoolean))), queryClauses @@ -420,7 +420,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.count(#keyPath(TestEntity1.testNumber))), queryClauses @@ -430,7 +430,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.count(#keyPath(TestEntity1.testNumber))), queryClauses @@ -440,7 +440,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.count(#keyPath(TestEntity1.testNumber))), queryClauses @@ -450,7 +450,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.count(#keyPath(TestEntity1.testNumber))), queryClauses @@ -460,7 +460,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.count(#keyPath(TestEntity1.testNumber))), queryClauses @@ -470,7 +470,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.count(#keyPath(TestEntity1.testNumber))), queryClauses @@ -480,7 +480,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.count(#keyPath(TestEntity1.testNumber))), queryClauses @@ -490,7 +490,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.count(#keyPath(TestEntity1.testNumber))), queryClauses @@ -500,7 +500,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.count(#keyPath(TestEntity1.testDecimal))), queryClauses @@ -509,7 +509,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.count(#keyPath(TestEntity1.testString))), queryClauses @@ -518,7 +518,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.count(#keyPath(TestEntity1.testString))), queryClauses @@ -527,7 +527,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.count(#keyPath(TestEntity1.testData))), queryClauses @@ -536,7 +536,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.count(#keyPath(TestEntity1.testData))), queryClauses @@ -545,7 +545,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.count(#keyPath(TestEntity1.testDate))), queryClauses @@ -554,7 +554,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.count(#keyPath(TestEntity1.testDate))), queryClauses @@ -563,7 +563,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.count(#keyPath(TestEntity1.testEntityID))), queryClauses @@ -587,7 +587,7 @@ class QueryTests: BaseTestDataTestCase { ] do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.maximum(#keyPath(TestEntity1.testBoolean))), queryClauses @@ -597,7 +597,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.maximum(#keyPath(TestEntity1.testNumber))), queryClauses @@ -607,7 +607,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.maximum(#keyPath(TestEntity1.testNumber))), queryClauses @@ -617,7 +617,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.maximum(#keyPath(TestEntity1.testNumber))), queryClauses @@ -627,7 +627,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.maximum(#keyPath(TestEntity1.testNumber))), queryClauses @@ -637,7 +637,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.maximum(#keyPath(TestEntity1.testNumber))), queryClauses @@ -647,7 +647,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.maximum(#keyPath(TestEntity1.testNumber))), queryClauses @@ -657,7 +657,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.maximum(#keyPath(TestEntity1.testNumber))), queryClauses @@ -667,7 +667,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.maximum(#keyPath(TestEntity1.testNumber))), queryClauses @@ -677,7 +677,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.maximum(#keyPath(TestEntity1.testDecimal))), queryClauses @@ -687,7 +687,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.maximum(#keyPath(TestEntity1.testString))), queryClauses @@ -697,7 +697,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.maximum(#keyPath(TestEntity1.testString))), queryClauses @@ -707,7 +707,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.maximum(#keyPath(TestEntity1.testData))), queryClauses @@ -717,7 +717,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.maximum(#keyPath(TestEntity1.testData))), queryClauses @@ -727,7 +727,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.maximum(#keyPath(TestEntity1.testDate))), queryClauses @@ -737,7 +737,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.maximum(#keyPath(TestEntity1.testDate))), queryClauses @@ -747,7 +747,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.maximum(#keyPath(TestEntity1.testEntityID))), queryClauses @@ -771,7 +771,7 @@ class QueryTests: BaseTestDataTestCase { ] do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.minimum(#keyPath(TestEntity1.testBoolean))), queryClauses @@ -781,7 +781,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.minimum(#keyPath(TestEntity1.testNumber))), queryClauses @@ -791,7 +791,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.minimum(#keyPath(TestEntity1.testNumber))), queryClauses @@ -801,7 +801,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.minimum(#keyPath(TestEntity1.testNumber))), queryClauses @@ -811,7 +811,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.minimum(#keyPath(TestEntity1.testNumber))), queryClauses @@ -821,7 +821,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.minimum(#keyPath(TestEntity1.testNumber))), queryClauses @@ -831,7 +831,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.minimum(#keyPath(TestEntity1.testNumber))), queryClauses @@ -841,7 +841,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.minimum(#keyPath(TestEntity1.testNumber))), queryClauses @@ -851,7 +851,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.minimum(#keyPath(TestEntity1.testNumber))), queryClauses @@ -861,7 +861,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.minimum(#keyPath(TestEntity1.testDecimal))), queryClauses @@ -871,7 +871,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.minimum(#keyPath(TestEntity1.testString))), queryClauses @@ -881,7 +881,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.minimum(#keyPath(TestEntity1.testString))), queryClauses @@ -891,7 +891,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.minimum(#keyPath(TestEntity1.testData))), queryClauses @@ -901,7 +901,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.minimum(#keyPath(TestEntity1.testData))), queryClauses @@ -911,7 +911,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.minimum(#keyPath(TestEntity1.testDate))), queryClauses @@ -921,7 +921,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.minimum(#keyPath(TestEntity1.testDate))), queryClauses @@ -931,7 +931,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.minimum(#keyPath(TestEntity1.testEntityID))), queryClauses @@ -955,7 +955,7 @@ class QueryTests: BaseTestDataTestCase { ] do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.sum(#keyPath(TestEntity1.testBoolean))), queryClauses @@ -965,7 +965,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.sum(#keyPath(TestEntity1.testNumber))), queryClauses @@ -975,7 +975,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.sum(#keyPath(TestEntity1.testNumber))), queryClauses @@ -985,7 +985,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.sum(#keyPath(TestEntity1.testNumber))), queryClauses @@ -995,7 +995,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.sum(#keyPath(TestEntity1.testNumber))), queryClauses @@ -1005,7 +1005,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.sum(#keyPath(TestEntity1.testNumber))), queryClauses @@ -1015,7 +1015,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.sum(#keyPath(TestEntity1.testNumber))), queryClauses @@ -1025,7 +1025,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.sum(#keyPath(TestEntity1.testNumber))), queryClauses @@ -1035,7 +1035,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.sum(#keyPath(TestEntity1.testNumber))), queryClauses @@ -1045,7 +1045,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.sum(#keyPath(TestEntity1.testDecimal))), queryClauses @@ -1055,7 +1055,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.sum(#keyPath(TestEntity1.testString))), queryClauses @@ -1064,7 +1064,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.sum(#keyPath(TestEntity1.testString))), queryClauses @@ -1073,7 +1073,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.sum(#keyPath(TestEntity1.testData))), queryClauses @@ -1082,7 +1082,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.sum(#keyPath(TestEntity1.testData))), queryClauses @@ -1091,7 +1091,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.sum(#keyPath(TestEntity1.testDate))), queryClauses @@ -1100,7 +1100,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.sum(#keyPath(TestEntity1.testDate))), queryClauses @@ -1109,7 +1109,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.sum(#keyPath(TestEntity1.testEntityID))), queryClauses @@ -1133,7 +1133,7 @@ class QueryTests: BaseTestDataTestCase { ] do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.objectID()), queryClauses @@ -1142,7 +1142,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.objectID()), queryClauses @@ -1151,7 +1151,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.objectID()), queryClauses @@ -1160,7 +1160,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.objectID()), queryClauses @@ -1169,7 +1169,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.objectID()), queryClauses @@ -1178,7 +1178,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.objectID()), queryClauses @@ -1187,7 +1187,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.objectID()), queryClauses @@ -1196,7 +1196,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.objectID()), queryClauses @@ -1205,7 +1205,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.objectID()), queryClauses @@ -1214,7 +1214,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.objectID()), queryClauses @@ -1223,7 +1223,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.objectID()), queryClauses @@ -1232,7 +1232,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.objectID()), queryClauses @@ -1241,7 +1241,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.objectID()), queryClauses @@ -1250,7 +1250,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.objectID()), queryClauses @@ -1259,7 +1259,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.objectID()), queryClauses @@ -1268,7 +1268,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.objectID()), queryClauses @@ -1277,7 +1277,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let value = stack.queryValue( + let value = try stack.queryValue( from, Select(.objectID()), queryClauses @@ -1302,7 +1302,7 @@ class QueryTests: BaseTestDataTestCase { ] do { - let values = stack.queryAttributes( + let values = try stack.queryAttributes( from, Select( #keyPath(TestEntity1.testBoolean), @@ -1353,7 +1353,7 @@ class QueryTests: BaseTestDataTestCase { let queryClauses: [QueryClause] = [] do { - let values = stack.queryAttributes( + let values = try stack.queryAttributes( from, Select( .sum(#keyPath(TestEntity1.testBoolean)), @@ -1380,7 +1380,7 @@ class QueryTests: BaseTestDataTestCase { } do { - let values = stack.queryAttributes( + let values = try stack.queryAttributes( from, Select( .sum(#keyPath(TestEntity1.testBoolean), as: "testSum"), diff --git a/CoreStoreTests/TransactionTests.swift b/CoreStoreTests/TransactionTests.swift index 318f9f4..9b45137 100644 --- a/CoreStoreTests/TransactionTests.swift +++ b/CoreStoreTests/TransactionTests.swift @@ -69,9 +69,9 @@ final class TransactionTests: BaseTestCase { self.checkExpectationsImmediately() XCTAssertTrue(hasChanges) - XCTAssertEqual(stack.fetchCount(From()), 1) + XCTAssertEqual(try stack.fetchCount(From()), 1) - let object = stack.fetchOne(From()) + let object = try stack.fetchOne(From()) XCTAssertNotNil(object) XCTAssertEqual(object?.fetchSource()?.unsafeContext(), stack.mainContext) XCTAssertEqual(object?.querySource()?.unsafeContext(), stack.mainContext) @@ -84,14 +84,14 @@ final class TransactionTests: BaseTestCase { do { let updateExpectation = self.expectation(description: "update") - let hasChanges: Bool = try! stack.perform( + let hasChanges: Bool = try stack.perform( synchronous: { (transaction) in defer { updateExpectation.fulfill() } - guard let object = transaction.fetchOne(From()) else { + guard let object = try transaction.fetchOne(From()) else { // TODO: convert fetch methods to throwing methods XCTFail() try transaction.cancel() @@ -107,9 +107,9 @@ final class TransactionTests: BaseTestCase { self.checkExpectationsImmediately() XCTAssertTrue(hasChanges) - XCTAssertEqual(stack.fetchCount(From()), 1) + XCTAssertEqual(try stack.fetchCount(From()), 1) - let object = stack.fetchOne(From()) + let object = try stack.fetchOne(From()) XCTAssertNotNil(object) XCTAssertEqual(object?.testEntityID, NSNumber(value: 1)) XCTAssertEqual(object?.testString, "string1_edit") @@ -128,7 +128,7 @@ final class TransactionTests: BaseTestCase { deleteExpectation.fulfill() } - let object = transaction.fetchOne(From()) + let object = try transaction.fetchOne(From()) transaction.delete(object) return transaction.hasChanges } @@ -141,9 +141,9 @@ final class TransactionTests: BaseTestCase { } self.checkExpectationsImmediately() - XCTAssertEqual(stack.fetchCount(From()), 0) + XCTAssertEqual(try stack.fetchCount(From()), 0) - let object = stack.fetchOne(From()) + let object = try stack.fetchOne(From()) XCTAssertNil(object) } } @@ -184,10 +184,10 @@ final class TransactionTests: BaseTestCase { } self.checkExpectationsImmediately() - XCTAssertEqual(stack.fetchCount(From("Config1")), 1) - XCTAssertEqual(stack.fetchCount(From(nil)), 0) + XCTAssertEqual(try stack.fetchCount(From("Config1")), 1) + XCTAssertEqual(try stack.fetchCount(From(nil)), 0) - let object = stack.fetchOne(From("Config1")) + let object = try stack.fetchOne(From("Config1")) XCTAssertNotNil(object) XCTAssertEqual(object?.testEntityID, NSNumber(value: 1)) XCTAssertEqual(object?.testString, "string1") @@ -206,7 +206,7 @@ final class TransactionTests: BaseTestCase { updateExpectation.fulfill() } - guard let object = transaction.fetchOne(From("Config1")) else { + guard let object = try transaction.fetchOne(From("Config1")) else { XCTFail() try transaction.cancel() @@ -226,10 +226,10 @@ final class TransactionTests: BaseTestCase { } self.checkExpectationsImmediately() - XCTAssertEqual(stack.fetchCount(From("Config1")), 1) - XCTAssertEqual(stack.fetchCount(From(nil)), 0) + XCTAssertEqual(try stack.fetchCount(From("Config1")), 1) + XCTAssertEqual(try stack.fetchCount(From(nil)), 0) - let object = stack.fetchOne(From("Config1")) + let object = try stack.fetchOne(From("Config1")) XCTAssertNotNil(object) XCTAssertEqual(object?.testEntityID, NSNumber(value: 1)) XCTAssertEqual(object?.testString, "string1_edit") @@ -248,7 +248,7 @@ final class TransactionTests: BaseTestCase { deleteExpectation.fulfill() } - let object = transaction.fetchOne(From("Config1")) + let object = try transaction.fetchOne(From("Config1")) transaction.delete(object) return transaction.hasChanges @@ -262,8 +262,8 @@ final class TransactionTests: BaseTestCase { } self.checkExpectationsImmediately() - XCTAssertEqual(stack.fetchCount(From("Config1")), 0) - XCTAssertEqual(stack.fetchCount(From(nil)), 0) + XCTAssertEqual(try stack.fetchCount(From("Config1")), 0) + XCTAssertEqual(try stack.fetchCount(From(nil)), 0) } } } @@ -294,9 +294,9 @@ final class TransactionTests: BaseTestCase { ) self.checkExpectationsImmediately() - XCTAssertEqual(stack.fetchCount(From()), 0) + XCTAssertEqual(try stack.fetchCount(From()), 0) - let object = stack.fetchOne(From()) + let object = try stack.fetchOne(From()) XCTAssertNil(object) } let testDate = Date() @@ -329,7 +329,7 @@ final class TransactionTests: BaseTestCase { updateDiscardExpectation.fulfill() } - guard let object = transaction.fetchOne(From()) else { + guard let object = try transaction.fetchOne(From()) else { XCTFail() try transaction.cancel() @@ -343,9 +343,9 @@ final class TransactionTests: BaseTestCase { ) self.checkExpectationsImmediately() - XCTAssertEqual(stack.fetchCount(From()), 1) + XCTAssertEqual(try stack.fetchCount(From()), 1) - let object = stack.fetchOne(From()) + let object = try stack.fetchOne(From()) XCTAssertNotNil(object) XCTAssertEqual(object?.testEntityID, NSNumber(value: 1)) XCTAssertEqual(object?.testString, "string1") @@ -362,7 +362,7 @@ final class TransactionTests: BaseTestCase { deleteDiscardExpectation.fulfill() } - guard let object = transaction.fetchOne(From()) else { + guard let object = try transaction.fetchOne(From()) else { XCTFail() try transaction.cancel() @@ -374,9 +374,9 @@ final class TransactionTests: BaseTestCase { ) self.checkExpectationsImmediately() - XCTAssertEqual(stack.fetchCount(From()), 1) + XCTAssertEqual(try stack.fetchCount(From()), 1) - let object = stack.fetchOne(From()) + let object = try stack.fetchOne(From()) XCTAssertNotNil(object) XCTAssertEqual(object?.testEntityID, NSNumber(value: 1)) XCTAssertEqual(object?.testString, "string1") @@ -520,19 +520,26 @@ final class TransactionTests: BaseTestCase { success: { (hasChanges) in XCTAssertTrue(hasChanges) - - XCTAssertEqual(stack.fetchCount(From()), 1) - - let object = stack.fetchOne(From()) - XCTAssertNotNil(object) - XCTAssertEqual(object?.fetchSource()?.unsafeContext(), stack.mainContext) - XCTAssertEqual(object?.querySource()?.unsafeContext(), stack.mainContext) - - XCTAssertEqual(object?.testEntityID, NSNumber(value: 1)) - XCTAssertEqual(object?.testString, "string1") - XCTAssertEqual(object?.testNumber, 100) - XCTAssertEqual(object?.testDate, testDate) - createExpectation.fulfill() + + do { + + XCTAssertEqual(try stack.fetchCount(From()), 1) + + let object = try stack.fetchOne(From()) + XCTAssertNotNil(object) + XCTAssertEqual(object?.fetchSource()?.unsafeContext(), stack.mainContext) + XCTAssertEqual(object?.querySource()?.unsafeContext(), stack.mainContext) + + XCTAssertEqual(object?.testEntityID, NSNumber(value: 1)) + XCTAssertEqual(object?.testString, "string1") + XCTAssertEqual(object?.testNumber, 100) + XCTAssertEqual(object?.testDate, testDate) + createExpectation.fulfill() + } + catch { + + XCTFail() + } }, failure: { _ in @@ -546,7 +553,7 @@ final class TransactionTests: BaseTestCase { stack.perform( asynchronous: { (transaction) -> Bool in - guard let object = transaction.fetchOne(From()) else { + guard let object = try transaction.fetchOne(From()) else { XCTFail() try transaction.cancel() @@ -560,16 +567,23 @@ final class TransactionTests: BaseTestCase { success: { (hasChanges) in XCTAssertTrue(hasChanges) - - XCTAssertEqual(stack.fetchCount(From()), 1) - - let object = stack.fetchOne(From()) - XCTAssertNotNil(object) - XCTAssertEqual(object?.testEntityID, NSNumber(value: 1)) - XCTAssertEqual(object?.testString, "string1_edit") - XCTAssertEqual(object?.testNumber, 200) - XCTAssertEqual(object?.testDate, Date.distantFuture) - updateExpectation.fulfill() + + do { + + XCTAssertEqual(try stack.fetchCount(From()), 1) + + let object = try stack.fetchOne(From()) + XCTAssertNotNil(object) + XCTAssertEqual(object?.testEntityID, NSNumber(value: 1)) + XCTAssertEqual(object?.testString, "string1_edit") + XCTAssertEqual(object?.testNumber, 200) + XCTAssertEqual(object?.testDate, Date.distantFuture) + updateExpectation.fulfill() + } + catch { + + XCTFail() + } }, failure: { _ in @@ -583,7 +597,7 @@ final class TransactionTests: BaseTestCase { stack.perform( asynchronous: { (transaction) -> Bool in - let object = transaction.fetchOne(From()) + let object = try transaction.fetchOne(From()) transaction.delete(object) return transaction.hasChanges @@ -591,12 +605,19 @@ final class TransactionTests: BaseTestCase { success: { (hasChanges) in XCTAssertTrue(hasChanges) - - XCTAssertEqual(stack.fetchCount(From()), 0) - - let object = stack.fetchOne(From()) - XCTAssertNil(object) - deleteExpectation.fulfill() + + do { + + XCTAssertEqual(try stack.fetchCount(From()), 0) + + let object = try stack.fetchOne(From()) + XCTAssertNil(object) + deleteExpectation.fulfill() + } + catch { + + XCTFail() + } }, failure: { _ in @@ -631,17 +652,24 @@ final class TransactionTests: BaseTestCase { success: { (hasChanges) in XCTAssertTrue(hasChanges) - - XCTAssertEqual(stack.fetchCount(From("Config1")), 1) - XCTAssertEqual(stack.fetchCount(From(nil)), 0) - - let object = stack.fetchOne(From("Config1")) - XCTAssertNotNil(object) - XCTAssertEqual(object?.testEntityID, NSNumber(value: 1)) - XCTAssertEqual(object?.testString, "string1") - XCTAssertEqual(object?.testNumber, 100) - XCTAssertEqual(object?.testDate, testDate) - createExpectation.fulfill() + + do { + + XCTAssertEqual(try stack.fetchCount(From("Config1")), 1) + XCTAssertEqual(try stack.fetchCount(From(nil)), 0) + + let object = try stack.fetchOne(From("Config1")) + XCTAssertNotNil(object) + XCTAssertEqual(object?.testEntityID, NSNumber(value: 1)) + XCTAssertEqual(object?.testString, "string1") + XCTAssertEqual(object?.testNumber, 100) + XCTAssertEqual(object?.testDate, testDate) + createExpectation.fulfill() + } + catch { + + XCTFail() + } }, failure: { _ in @@ -655,7 +683,7 @@ final class TransactionTests: BaseTestCase { stack.perform( asynchronous: { (transaction) -> Bool in - guard let object = transaction.fetchOne(From("Config1")) else { + guard let object = try transaction.fetchOne(From("Config1")) else { XCTFail() try transaction.cancel() @@ -669,17 +697,24 @@ final class TransactionTests: BaseTestCase { success: { (hasChanges) in XCTAssertTrue(hasChanges) - - XCTAssertEqual(stack.fetchCount(From("Config1")), 1) - XCTAssertEqual(stack.fetchCount(From(nil)), 0) - - let object = stack.fetchOne(From("Config1")) - XCTAssertNotNil(object) - XCTAssertEqual(object?.testEntityID, NSNumber(value: 1)) - XCTAssertEqual(object?.testString, "string1_edit") - XCTAssertEqual(object?.testNumber, 200) - XCTAssertEqual(object?.testDate, Date.distantFuture) - updateExpectation.fulfill() + + do { + + XCTAssertEqual(try stack.fetchCount(From("Config1")), 1) + XCTAssertEqual(try stack.fetchCount(From(nil)), 0) + + let object = try stack.fetchOne(From("Config1")) + XCTAssertNotNil(object) + XCTAssertEqual(object?.testEntityID, NSNumber(value: 1)) + XCTAssertEqual(object?.testString, "string1_edit") + XCTAssertEqual(object?.testNumber, 200) + XCTAssertEqual(object?.testDate, Date.distantFuture) + updateExpectation.fulfill() + } + catch { + + XCTFail() + } }, failure: { _ in @@ -693,7 +728,7 @@ final class TransactionTests: BaseTestCase { stack.perform( asynchronous: { (transaction) -> Bool in - let object = transaction.fetchOne(From("Config1")) + let object = try transaction.fetchOne(From("Config1")) transaction.delete(object) return transaction.hasChanges @@ -701,11 +736,18 @@ final class TransactionTests: BaseTestCase { success: { (hasChanges) in XCTAssertTrue(hasChanges) - - XCTAssertEqual(stack.fetchCount(From("Config1")), 0) - XCTAssertEqual(stack.fetchCount(From(nil)), 0) - - deleteExpectation.fulfill() + + do { + + XCTAssertEqual(try stack.fetchCount(From("Config1")), 0) + XCTAssertEqual(try stack.fetchCount(From(nil)), 0) + + deleteExpectation.fulfill() + } + catch { + + XCTFail() + } }, failure: { _ in @@ -754,8 +796,8 @@ final class TransactionTests: BaseTestCase { stack.perform( asynchronous: { (transaction) -> Bool in - XCTAssertEqual(transaction.fetchCount(From()), 0) - XCTAssertNil(transaction.fetchOne(From())) + XCTAssertEqual(try transaction.fetchCount(From()), 0) + XCTAssertNil(try transaction.fetchOne(From())) let object = transaction.create(Into()) object.testEntityID = NSNumber(value: 1) @@ -782,7 +824,7 @@ final class TransactionTests: BaseTestCase { stack.perform( asynchronous: { (transaction) -> Void in - guard let object = transaction.fetchOne(From()) else { + guard let object = try transaction.fetchOne(From()) else { XCTFail() return @@ -811,9 +853,9 @@ final class TransactionTests: BaseTestCase { stack.perform( asynchronous: { (transaction) -> Void in - XCTAssertEqual(transaction.fetchCount(From()), 1) + XCTAssertEqual(try transaction.fetchCount(From()), 1) - guard let object = transaction.fetchOne(From()) else { + guard let object = try transaction.fetchOne(From()) else { XCTFail() try transaction.cancel() @@ -835,15 +877,22 @@ final class TransactionTests: BaseTestCase { failure: { (error) in XCTAssertEqual(error, CoreStoreError.userCancelled) - XCTAssertEqual(stack.fetchCount(From()), 1) - - let object = stack.fetchOne(From()) - XCTAssertNotNil(object) - XCTAssertEqual(object?.testEntityID, NSNumber(value: 1)) - XCTAssertEqual(object?.testString, "string1") - XCTAssertEqual(object?.testNumber, 100) - XCTAssertEqual(object?.testDate, testDate) - deleteDiscardExpectation.fulfill() + do { + + XCTAssertEqual(try stack.fetchCount(From()), 1) + + let object = try stack.fetchOne(From()) + XCTAssertNotNil(object) + XCTAssertEqual(object?.testEntityID, NSNumber(value: 1)) + XCTAssertEqual(object?.testString, "string1") + XCTAssertEqual(object?.testNumber, 100) + XCTAssertEqual(object?.testDate, testDate) + deleteDiscardExpectation.fulfill() + } + catch { + + XCTFail() + } } ) } @@ -878,9 +927,9 @@ final class TransactionTests: BaseTestCase { XCTAssertTrue(transaction.hasChanges) try transaction.commitAndWait() - XCTAssertEqual(stack.fetchCount(From()), 1) + XCTAssertEqual(try stack.fetchCount(From()), 1) - let object = stack.fetchOne(From()) + let object = try stack.fetchOne(From()) XCTAssertNotNil(object) XCTAssertEqual(object?.fetchSource()?.unsafeContext(), stack.mainContext) XCTAssertEqual(object?.querySource()?.unsafeContext(), stack.mainContext) @@ -897,7 +946,7 @@ final class TransactionTests: BaseTestCase { } do { - guard let object = transaction.fetchOne(From()) else { + guard let object = try transaction.fetchOne(From()) else { XCTFail() return @@ -911,9 +960,9 @@ final class TransactionTests: BaseTestCase { XCTAssertTrue(transaction.hasChanges) try transaction.commitAndWait() - XCTAssertEqual(stack.fetchCount(From()), 1) + XCTAssertEqual(try stack.fetchCount(From()), 1) - let object = stack.fetchOne(From()) + let object = try stack.fetchOne(From()) XCTAssertNotNil(object) XCTAssertEqual(object?.testEntityID, NSNumber(value: 1)) XCTAssertEqual(object?.testString, "string1_edit") @@ -927,7 +976,7 @@ final class TransactionTests: BaseTestCase { } do { - let object = transaction.fetchOne(From()) + let object = try transaction.fetchOne(From()) transaction.delete(object) do { @@ -935,8 +984,8 @@ final class TransactionTests: BaseTestCase { XCTAssertTrue(transaction.hasChanges) try transaction.commitAndWait() - XCTAssertEqual(stack.fetchCount(From()), 0) - XCTAssertNil(stack.fetchOne(From())) + XCTAssertEqual(try stack.fetchCount(From()), 0) + XCTAssertNil(try stack.fetchOne(From())) } catch { @@ -967,10 +1016,10 @@ final class TransactionTests: BaseTestCase { XCTAssertTrue(transaction.hasChanges) try transaction.commitAndWait() - XCTAssertEqual(stack.fetchCount(From("Config1")), 1) - XCTAssertEqual(stack.fetchCount(From(nil)), 0) + XCTAssertEqual(try stack.fetchCount(From("Config1")), 1) + XCTAssertEqual(try stack.fetchCount(From(nil)), 0) - let object = stack.fetchOne(From("Config1")) + let object = try stack.fetchOne(From("Config1")) XCTAssertNotNil(object) XCTAssertEqual(object?.testEntityID, NSNumber(value: 1)) XCTAssertEqual(object?.testString, "string1") @@ -984,7 +1033,7 @@ final class TransactionTests: BaseTestCase { } do { - guard let object = transaction.fetchOne(From("Config1")) else { + guard let object = try transaction.fetchOne(From("Config1")) else { XCTFail() return @@ -998,10 +1047,10 @@ final class TransactionTests: BaseTestCase { XCTAssertTrue(transaction.hasChanges) try transaction.commitAndWait() - XCTAssertEqual(stack.fetchCount(From("Config1")), 1) - XCTAssertEqual(stack.fetchCount(From(nil)), 0) + XCTAssertEqual(try stack.fetchCount(From("Config1")), 1) + XCTAssertEqual(try stack.fetchCount(From(nil)), 0) - let object = stack.fetchOne(From("Config1")) + let object = try stack.fetchOne(From("Config1")) XCTAssertNotNil(object) XCTAssertEqual(object?.testEntityID, NSNumber(value: 1)) XCTAssertEqual(object?.testString, "string1_edit") @@ -1015,7 +1064,7 @@ final class TransactionTests: BaseTestCase { } do { - let object = transaction.fetchOne(From("Config1")) + let object = try transaction.fetchOne(From("Config1")) transaction.delete(object) do { @@ -1023,8 +1072,8 @@ final class TransactionTests: BaseTestCase { XCTAssertTrue(transaction.hasChanges) try transaction.commitAndWait() - XCTAssertEqual(stack.fetchCount(From("Config1")), 0) - XCTAssertEqual(stack.fetchCount(From(nil)), 0) + XCTAssertEqual(try stack.fetchCount(From("Config1")), 0) + XCTAssertEqual(try stack.fetchCount(From(nil)), 0) } catch { @@ -1050,11 +1099,11 @@ final class TransactionTests: BaseTestCase { transaction.rollback() - XCTAssertEqual(transaction.fetchCount(From()), 0) - XCTAssertNil(transaction.fetchOne(From())) + XCTAssertEqual(try transaction.fetchCount(From()), 0) + XCTAssertNil(try transaction.fetchOne(From())) - XCTAssertEqual(stack.fetchCount(From()), 0) - XCTAssertNil(stack.fetchOne(From())) + XCTAssertEqual(try stack.fetchCount(From()), 0) + XCTAssertNil(try stack.fetchOne(From())) } let testDate = Date() @@ -1079,7 +1128,7 @@ final class TransactionTests: BaseTestCase { do { - guard let object = transaction.fetchOne(From()) else { + guard let object = try transaction.fetchOne(From()) else { XCTFail() return @@ -1090,8 +1139,8 @@ final class TransactionTests: BaseTestCase { transaction.rollback() - XCTAssertEqual(transaction.fetchCount(From()), 1) - if let object = transaction.fetchOne(From()) { + XCTAssertEqual(try transaction.fetchCount(From()), 1) + if let object = try transaction.fetchOne(From()) { XCTAssertEqual(object.testEntityID, NSNumber(value: 1)) XCTAssertEqual(object.testString, "string1") @@ -1103,8 +1152,8 @@ final class TransactionTests: BaseTestCase { XCTFail() } - XCTAssertEqual(stack.fetchCount(From()), 1) - if let object = stack.fetchOne(From()) { + XCTAssertEqual(try stack.fetchCount(From()), 1) + if let object = try stack.fetchOne(From()) { XCTAssertEqual(object.testEntityID, NSNumber(value: 1)) XCTAssertEqual(object.testString, "string1") @@ -1119,7 +1168,7 @@ final class TransactionTests: BaseTestCase { do { - guard let object = transaction.fetchOne(From()) else { + guard let object = try transaction.fetchOne(From()) else { XCTFail() return @@ -1128,8 +1177,8 @@ final class TransactionTests: BaseTestCase { transaction.rollback() - XCTAssertEqual(transaction.fetchCount(From()), 1) - if let object = transaction.fetchOne(From()) { + XCTAssertEqual(try transaction.fetchCount(From()), 1) + if let object = try transaction.fetchOne(From()) { XCTAssertEqual(object.testEntityID, NSNumber(value: 1)) XCTAssertEqual(object.testString, "string1") @@ -1141,8 +1190,8 @@ final class TransactionTests: BaseTestCase { XCTFail() } - XCTAssertEqual(stack.fetchCount(From()), 1) - if let object = stack.fetchOne(From()) { + XCTAssertEqual(try stack.fetchCount(From()), 1) + if let object = try stack.fetchOne(From()) { XCTAssertEqual(object.testEntityID, NSNumber(value: 1)) XCTAssertEqual(object.testString, "string1") diff --git a/Sources/BaseDataTransaction+Importing.swift b/Sources/BaseDataTransaction+Importing.swift index c55397d..15ed01c 100644 --- a/Sources/BaseDataTransaction+Importing.swift +++ b/Sources/BaseDataTransaction+Importing.swift @@ -151,7 +151,7 @@ public extension BaseDataTransaction { return nil } - if let object = self.fetchOne(From(entityType), Where(uniqueIDKeyPath, isEqualTo: uniqueIDValue)) { + if let object = try self.fetchOne(From(entityType), Where(uniqueIDKeyPath, isEqualTo: uniqueIDValue)) { guard entityType.shouldUpdate(from: source, in: self) else { @@ -215,7 +215,8 @@ public extension BaseDataTransaction { importSourceByID = try autoreleasepool { try preProcess(importSourceByID) } var existingObjectsByID = Dictionary() - self.fetchAll(From(entityType), Where(entityType.uniqueIDKeyPath, isMemberOf: sortedIDs))? + try self + .fetchAll(From(entityType), Where(entityType.uniqueIDKeyPath, isMemberOf: sortedIDs)) .forEach { existingObjectsByID[$0.uniqueIDValue] = $0 } var processedObjectIDs = Set() diff --git a/Sources/BaseDataTransaction+Querying.swift b/Sources/BaseDataTransaction+Querying.swift index 4d712c5..82c9e02 100644 --- a/Sources/BaseDataTransaction+Querying.swift +++ b/Sources/BaseDataTransaction+Querying.swift @@ -39,13 +39,13 @@ 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...) throws -> Int { CoreStore.assert( self.isRunningInAllowedQueue(), "Attempted to delete from a \(cs_typeName(self)) outside its designated queue." ) - return self.context.deleteAll(from, deleteClauses) + return try self.context.deleteAll(from, deleteClauses) } /** @@ -56,13 +56,13 @@ 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]) throws -> Int { CoreStore.assert( self.isRunningInAllowedQueue(), "Attempted to delete from a \(cs_typeName(self)) outside its designated queue." ) - return self.context.deleteAll(from, deleteClauses) + return try self.context.deleteAll(from, deleteClauses) } /** @@ -74,14 +74,14 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - returns: the number of `DynamicObject`s deleted */ @discardableResult - public func deleteAll(_ clauseChain: B) -> Int? { + public func deleteAll(_ clauseChain: B) throws -> Int { CoreStore.assert( self.isRunningInAllowedQueue(), "Attempted to delete from a \(cs_typeName(self)) outside its designated queue." ) - return self.context.deleteAll(clauseChain.from, clauseChain.fetchClauses) + return try self.context.deleteAll(clauseChain.from, clauseChain.fetchClauses) } @@ -297,13 +297,13 @@ 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...) throws -> NSManagedObjectID? { CoreStore.assert( self.isRunningInAllowedQueue(), "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) - return self.context.fetchObjectID(from, fetchClauses) + return try self.context.fetchObjectID(from, fetchClauses) } /** @@ -313,13 +313,13 @@ 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]) throws -> NSManagedObjectID? { CoreStore.assert( self.isRunningInAllowedQueue(), "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) - return self.context.fetchObjectID(from, fetchClauses) + return try self.context.fetchObjectID(from, fetchClauses) } /** @@ -334,13 +334,13 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType` */ - public func fetchObjectID(_ clauseChain: B) -> NSManagedObjectID? { + public func fetchObjectID(_ clauseChain: B) throws -> NSManagedObjectID? { CoreStore.assert( self.isRunningInAllowedQueue(), "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) - return self.context.fetchObjectID(clauseChain) + return try self.context.fetchObjectID(clauseChain) } /** @@ -350,13 +350,13 @@ 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...) throws -> [NSManagedObjectID] { CoreStore.assert( self.isRunningInAllowedQueue(), "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) - return self.context.fetchObjectIDs(from, fetchClauses) + return try self.context.fetchObjectIDs(from, fetchClauses) } /** @@ -366,13 +366,13 @@ 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]) throws -> [NSManagedObjectID] { CoreStore.assert( self.isRunningInAllowedQueue(), "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) - return self.context.fetchObjectIDs(from, fetchClauses) + return try self.context.fetchObjectIDs(from, fetchClauses) } /** @@ -387,13 +387,13 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` */ - public func fetchObjectIDs(_ clauseChain: B) -> [NSManagedObjectID]? { + public func fetchObjectIDs(_ clauseChain: B) throws -> [NSManagedObjectID] { CoreStore.assert( self.isRunningInAllowedQueue(), "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) - return self.context.fetchObjectIDs(clauseChain) + return try self.context.fetchObjectIDs(clauseChain) } @@ -409,13 +409,13 @@ 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...) throws -> U? { CoreStore.assert( self.isRunningInAllowedQueue(), "Attempted to query from a \(cs_typeName(self)) outside its designated queue." ) - return self.context.queryValue(from, selectClause, queryClauses) + return try self.context.queryValue(from, selectClause, queryClauses) } /** @@ -428,13 +428,13 @@ 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]) throws -> U? { CoreStore.assert( self.isRunningInAllowedQueue(), "Attempted to query from a \(cs_typeName(self)) outside its designated queue." ) - return self.context.queryValue(from, selectClause, queryClauses) + return try self.context.queryValue(from, selectClause, queryClauses) } /** @@ -451,13 +451,13 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter clauseChain: a `QueryChainableBuilderType` indicating the property/aggregate to fetch and the series of queries for the request. - returns: the result of the the query as specified by the `QueryChainableBuilderType` */ - public func queryValue(_ clauseChain: B) -> B.ResultType? where B.ResultType: QueryableAttributeType { + public func queryValue(_ clauseChain: B) throws -> B.ResultType? where B.ResultType: QueryableAttributeType { CoreStore.assert( self.isRunningInAllowedQueue(), "Attempted to query from a \(cs_typeName(self)) outside its designated queue." ) - return self.context.queryValue(clauseChain.from, clauseChain.select, clauseChain.queryClauses) + return try self.context.queryValue(clauseChain.from, clauseChain.select, clauseChain.queryClauses) } /** @@ -470,13 +470,13 @@ 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...) throws -> [[String: Any]] { CoreStore.assert( self.isRunningInAllowedQueue(), "Attempted to query from a \(cs_typeName(self)) outside its designated queue." ) - return self.context.queryAttributes(from, selectClause, queryClauses) + return try self.context.queryAttributes(from, selectClause, queryClauses) } /** @@ -489,13 +489,13 @@ 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]) throws -> [[String: Any]] { CoreStore.assert( self.isRunningInAllowedQueue(), "Attempted to query from a \(cs_typeName(self)) outside its designated queue." ) - return self.context.queryAttributes(from, selectClause, queryClauses) + return try self.context.queryAttributes(from, selectClause, queryClauses) } /** @@ -521,13 +521,13 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter clauseChain: a `QueryChainableBuilderType` indicating the properties to fetch and the series of queries for the request. - returns: the result of the the query as specified by the `QueryChainableBuilderType` */ - public func queryAttributes(_ clauseChain: B) -> [[String: Any]]? where B.ResultType == NSDictionary { + public func queryAttributes(_ clauseChain: B) throws -> [[String: Any]] where B.ResultType == NSDictionary { CoreStore.assert( self.isRunningInAllowedQueue(), "Attempted to query from a \(cs_typeName(self)) outside its designated queue." ) - return self.context.queryAttributes(clauseChain.from, clauseChain.select, clauseChain.queryClauses) + return try self.context.queryAttributes(clauseChain.from, clauseChain.select, clauseChain.queryClauses) } diff --git a/Sources/CSBaseDataTransaction+Querying.swift b/Sources/CSBaseDataTransaction+Querying.swift index 357fe66..47ea636 100644 --- a/Sources/CSBaseDataTransaction+Querying.swift +++ b/Sources/CSBaseDataTransaction+Querying.swift @@ -93,7 +93,8 @@ public extension CSBaseDataTransaction { self.swiftTransaction.isRunningInAllowedQueue(), "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) - return self.swiftTransaction.context.fetchOne(from, fetchClauses) + return (try? self.swiftTransaction.context.fetchOne(from, fetchClauses))? + .flatMap({ $0 }) } /** @@ -110,7 +111,8 @@ public extension CSBaseDataTransaction { self.swiftTransaction.isRunningInAllowedQueue(), "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) - return self.swiftTransaction.context.fetchAll(from, fetchClauses) + return (try? self.swiftTransaction.context.fetchAll(from, fetchClauses)) + .flatMap({ $0 }) } /** @@ -127,9 +129,8 @@ public extension CSBaseDataTransaction { self.swiftTransaction.isRunningInAllowedQueue(), "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) - return self.swiftTransaction.context - .fetchCount(from, fetchClauses) - .flatMap { NSNumber(value: $0) } + return (try? self.swiftTransaction.context.fetchCount(from, fetchClauses)) + .flatMap({ NSNumber(value: $0) }) } /** @@ -146,7 +147,8 @@ public extension CSBaseDataTransaction { self.swiftTransaction.isRunningInAllowedQueue(), "Attempted to fetch from a \(cs_typeName(self)) outside its designated queue." ) - return self.swiftTransaction.context.fetchObjectID(from, fetchClauses) + return (try? self.swiftTransaction.context.fetchObjectID(from, fetchClauses)) + .flatMap({ $0 }) } /** @@ -166,7 +168,8 @@ public extension CSBaseDataTransaction { self.swiftTransaction.isRunningInAllowedQueue(), "Attempted to query from a \(cs_typeName(self)) outside its designated queue." ) - return self.swiftTransaction.context.queryValue(from, selectClause, queryClauses) + return (try? self.swiftTransaction.context.queryValue(from, selectClause, queryClauses)) + .flatMap({ $0 }) } /** @@ -186,6 +189,7 @@ public extension CSBaseDataTransaction { self.swiftTransaction.isRunningInAllowedQueue(), "Attempted to query from a \(cs_typeName(self)) outside its designated queue." ) - return self.swiftTransaction.context.queryAttributes(from, selectClause, queryClauses) + return (try? self.swiftTransaction.context.queryAttributes(from, selectClause, queryClauses)) + .flatMap({ $0 }) } } diff --git a/Sources/CSDataStack+Querying.swift b/Sources/CSDataStack+Querying.swift index 9d5bfa0..3e38838 100644 --- a/Sources/CSDataStack+Querying.swift +++ b/Sources/CSDataStack+Querying.swift @@ -93,7 +93,8 @@ public extension CSDataStack { Thread.isMainThread, "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) - return self.bridgeToSwift.mainContext.fetchOne(from, fetchClauses) + return (try? self.bridgeToSwift.mainContext.fetchOne(from, fetchClauses))? + .flatMap({ $0 }) } /** @@ -110,7 +111,8 @@ public extension CSDataStack { Thread.isMainThread, "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) - return self.bridgeToSwift.mainContext.fetchAll(from, fetchClauses) + return (try? self.bridgeToSwift.mainContext.fetchAll(from, fetchClauses)) + .flatMap({ $0 }) } /** @@ -127,9 +129,8 @@ public extension CSDataStack { Thread.isMainThread, "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) - return self.bridgeToSwift.mainContext - .fetchCount(from, fetchClauses) - .flatMap { NSNumber(value: $0) } + return (try? self.bridgeToSwift.mainContext.fetchCount(from, fetchClauses)) + .flatMap({ NSNumber(value: $0) }) } /** @@ -146,7 +147,8 @@ public extension CSDataStack { Thread.isMainThread, "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) - return self.bridgeToSwift.mainContext.fetchObjectID(from, fetchClauses) + return (try? self.bridgeToSwift.mainContext.fetchObjectID(from, fetchClauses))? + .flatMap({ $0 }) } /** @@ -163,7 +165,8 @@ public extension CSDataStack { Thread.isMainThread, "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) - return self.bridgeToSwift.mainContext.fetchObjectIDs(from, fetchClauses) + return (try? self.bridgeToSwift.mainContext.fetchObjectIDs(from, fetchClauses)) + .flatMap({ $0 }) } /** @@ -183,7 +186,8 @@ public extension CSDataStack { Thread.isMainThread, "Attempted to query from a \(cs_typeName(self)) outside the main thread." ) - return self.bridgeToSwift.mainContext.queryValue(from, selectClause, queryClauses) + return (try? self.bridgeToSwift.mainContext.queryValue(from, selectClause, queryClauses)) + .flatMap({ $0 }) } /** @@ -203,6 +207,7 @@ public extension CSDataStack { Thread.isMainThread, "Attempted to query from a \(cs_typeName(self)) outside the main thread." ) - return self.bridgeToSwift.mainContext.queryAttributes(from, selectClause, queryClauses) + return (try? self.bridgeToSwift.mainContext.queryAttributes(from, selectClause, queryClauses)) + .flatMap({ $0 }) } } diff --git a/Sources/CoreStore+CustomDebugStringConvertible.swift b/Sources/CoreStore+CustomDebugStringConvertible.swift index ab92f8c..b94fe28 100644 --- a/Sources/CoreStore+CustomDebugStringConvertible.swift +++ b/Sources/CoreStore+CustomDebugStringConvertible.swift @@ -152,6 +152,10 @@ extension CoreStoreError: CustomDebugStringConvertible, CoreStoreDebugStringConv case .userCancelled: firstLine = ".userCancelled" + + case .persistentStoreNotFound(let entity): + firstLine = ".persistentStoreNotFound" + info.append(("entity", entity)) } return createFormattedString( diff --git a/Sources/CoreStore+Querying.swift b/Sources/CoreStore+Querying.swift index 2976a28..49fe4ae 100644 --- a/Sources/CoreStore+Querying.swift +++ b/Sources/CoreStore+Querying.swift @@ -205,9 +205,9 @@ 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...) throws -> NSManagedObjectID? { - return self.defaultStack.fetchObjectID(from, fetchClauses) + return try self.defaultStack.fetchObjectID(from, fetchClauses) } /** @@ -217,9 +217,9 @@ 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]) throws -> NSManagedObjectID? { - return self.defaultStack.fetchObjectID(from, fetchClauses) + return try self.defaultStack.fetchObjectID(from, fetchClauses) } /** @@ -234,9 +234,9 @@ public extension CoreStore { - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType` */ - public static func fetchObjectID(_ clauseChain: B) -> NSManagedObjectID? { + public static func fetchObjectID(_ clauseChain: B) throws -> NSManagedObjectID? { - return self.defaultStack.fetchObjectID(clauseChain) + return try self.defaultStack.fetchObjectID(clauseChain) } /** @@ -246,9 +246,9 @@ 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...) throws -> [NSManagedObjectID] { - return self.defaultStack.fetchObjectIDs(from, fetchClauses) + return try self.defaultStack.fetchObjectIDs(from, fetchClauses) } /** @@ -258,9 +258,9 @@ 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]) throws -> [NSManagedObjectID] { - return self.defaultStack.fetchObjectIDs(from, fetchClauses) + return try self.defaultStack.fetchObjectIDs(from, fetchClauses) } /** @@ -275,9 +275,9 @@ public extension CoreStore { - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` */ - public static func fetchObjectIDs(_ clauseChain: B) -> [NSManagedObjectID]? { + public static func fetchObjectIDs(_ clauseChain: B) throws -> [NSManagedObjectID] { - return self.defaultStack.fetchObjectIDs(clauseChain) + return try self.defaultStack.fetchObjectIDs(clauseChain) } /** @@ -290,9 +290,9 @@ 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...) throws -> U? { - return self.defaultStack.queryValue(from, selectClause, queryClauses) + return try self.defaultStack.queryValue(from, selectClause, queryClauses) } /** @@ -305,9 +305,9 @@ 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]) throws -> U? { - return self.defaultStack.queryValue(from, selectClause, queryClauses) + return try self.defaultStack.queryValue(from, selectClause, queryClauses) } /** @@ -324,9 +324,9 @@ public extension CoreStore { - parameter clauseChain: a `QueryChainableBuilderType` indicating the property/aggregate to fetch and the series of queries for the request. - returns: the result of the the query as specified by the `QueryChainableBuilderType` */ - public static func queryValue(_ clauseChain: B) -> B.ResultType? where B.ResultType: QueryableAttributeType { + public static func queryValue(_ clauseChain: B) throws -> B.ResultType? where B.ResultType: QueryableAttributeType { - return self.defaultStack.queryValue(clauseChain) + return try self.defaultStack.queryValue(clauseChain) } /** @@ -339,9 +339,9 @@ 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...) throws -> [[String: Any]] { - return self.defaultStack.queryAttributes(from, selectClause, queryClauses) + return try self.defaultStack.queryAttributes(from, selectClause, queryClauses) } /** @@ -354,9 +354,9 @@ 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]) throws -> [[String: Any]] { - return self.defaultStack.queryAttributes(from, selectClause, queryClauses) + return try self.defaultStack.queryAttributes(from, selectClause, queryClauses) } /** @@ -382,8 +382,8 @@ public extension CoreStore { - parameter clauseChain: a `QueryChainableBuilderType` indicating the properties to fetch and the series of queries for the request. - returns: the result of the the query as specified by the `QueryChainableBuilderType` */ - public static func queryAttributes(_ clauseChain: B) -> [[String: Any]]? where B.ResultType == NSDictionary { + public static func queryAttributes(_ clauseChain: B) throws -> [[String: Any]] where B.ResultType == NSDictionary { - return self.defaultStack.queryAttributes(clauseChain) + return try self.defaultStack.queryAttributes(clauseChain) } } diff --git a/Sources/CoreStoreFetchedResultsController.swift b/Sources/CoreStoreFetchedResultsController.swift index 5cad260..3638362 100644 --- a/Sources/CoreStoreFetchedResultsController.swift +++ b/Sources/CoreStoreFetchedResultsController.swift @@ -49,7 +49,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll @nonobjc internal init(context: NSManagedObjectContext, fetchRequest: NSFetchRequest, from: From, sectionBy: SectionBy? = nil, applyFetchClauses: @escaping (_ fetchRequest: NSFetchRequest) -> Void) { - _ = from.applyToFetchRequest( + _ = try? from.applyToFetchRequest( fetchRequest, context: context, applyAffectedStores: false @@ -58,7 +58,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll self.reapplyAffectedStores = { fetchRequest, context in - return try rom.applyAffectedStoresForFetchedRequest(fetchRequest, context: context) + try from.applyAffectedStoresForFetchedRequest(fetchRequest, context: context) } super.init( @@ -91,5 +91,5 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll // MARK: Private @nonobjc - private let reapplyAffectedStores: (_ fetchRequest: NSFetchRequest, _ context: NSManagedObjectContext) throws -> Bool + private let reapplyAffectedStores: (_ fetchRequest: NSFetchRequest, _ context: NSManagedObjectContext) throws -> Void } diff --git a/Sources/DataStack+Querying.swift b/Sources/DataStack+Querying.swift index 1d07566..411ca10 100644 --- a/Sources/DataStack+Querying.swift +++ b/Sources/DataStack+Querying.swift @@ -243,13 +243,13 @@ 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...) throws -> NSManagedObjectID? { CoreStore.assert( Thread.isMainThread, "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) - return self.mainContext.fetchObjectID(from, fetchClauses) + return try self.mainContext.fetchObjectID(from, fetchClauses) } /** @@ -259,13 +259,13 @@ 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]) throws -> NSManagedObjectID? { CoreStore.assert( Thread.isMainThread, "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) - return self.mainContext.fetchObjectID(from, fetchClauses) + return try self.mainContext.fetchObjectID(from, fetchClauses) } /** @@ -280,13 +280,13 @@ extension DataStack: FetchableSource, QueryableSource { - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType` */ - public func fetchObjectID(_ clauseChain: B) -> NSManagedObjectID? { + public func fetchObjectID(_ clauseChain: B) throws -> NSManagedObjectID? { CoreStore.assert( Thread.isMainThread, "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) - return self.mainContext.fetchObjectID(clauseChain) + return try self.mainContext.fetchObjectID(clauseChain) } /** @@ -296,13 +296,13 @@ 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...) throws -> [NSManagedObjectID] { CoreStore.assert( Thread.isMainThread, "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) - return self.mainContext.fetchObjectIDs(from, fetchClauses) + return try self.mainContext.fetchObjectIDs(from, fetchClauses) } /** @@ -312,13 +312,13 @@ 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]) throws -> [NSManagedObjectID] { CoreStore.assert( Thread.isMainThread, "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) - return self.mainContext.fetchObjectIDs(from, fetchClauses) + return try self.mainContext.fetchObjectIDs(from, fetchClauses) } /** @@ -333,13 +333,13 @@ extension DataStack: FetchableSource, QueryableSource { - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` */ - public func fetchObjectIDs(_ clauseChain: B) -> [NSManagedObjectID]? { + public func fetchObjectIDs(_ clauseChain: B) throws -> [NSManagedObjectID] { CoreStore.assert( Thread.isMainThread, "Attempted to fetch from a \(cs_typeName(self)) outside the main thread." ) - return self.mainContext.fetchObjectIDs(clauseChain) + return try self.mainContext.fetchObjectIDs(clauseChain) } @@ -355,13 +355,13 @@ 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...) throws -> U? { CoreStore.assert( Thread.isMainThread, "Attempted to query from a \(cs_typeName(self)) outside the main thread." ) - return self.mainContext.queryValue(from, selectClause, queryClauses) + return try self.mainContext.queryValue(from, selectClause, queryClauses) } /** @@ -374,13 +374,13 @@ 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]) throws -> U? { CoreStore.assert( Thread.isMainThread, "Attempted to query from a \(cs_typeName(self)) outside the main thread." ) - return self.mainContext.queryValue(from, selectClause, queryClauses) + return try self.mainContext.queryValue(from, selectClause, queryClauses) } /** @@ -397,13 +397,13 @@ extension DataStack: FetchableSource, QueryableSource { - parameter clauseChain: a `QueryChainableBuilderType` indicating the property/aggregate to fetch and the series of queries for the request. - returns: the result of the the query as specified by the `QueryChainableBuilderType` */ - public func queryValue(_ clauseChain: B) -> B.ResultType? where B.ResultType: QueryableAttributeType { + public func queryValue(_ clauseChain: B) throws -> B.ResultType? where B.ResultType: QueryableAttributeType { CoreStore.assert( Thread.isMainThread, "Attempted to query from a \(cs_typeName(self)) outside the main thread." ) - return self.mainContext.queryValue(clauseChain.from, clauseChain.select, clauseChain.queryClauses) + return try self.mainContext.queryValue(clauseChain.from, clauseChain.select, clauseChain.queryClauses) } /** @@ -416,13 +416,13 @@ 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...) throws -> [[String: Any]] { CoreStore.assert( Thread.isMainThread, "Attempted to query from a \(cs_typeName(self)) outside the main thread." ) - return self.mainContext.queryAttributes(from, selectClause, queryClauses) + return try self.mainContext.queryAttributes(from, selectClause, queryClauses) } /** @@ -435,13 +435,13 @@ 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]) throws -> [[String: Any]] { CoreStore.assert( Thread.isMainThread, "Attempted to query from a \(cs_typeName(self)) outside the main thread." ) - return self.mainContext.queryAttributes(from, selectClause, queryClauses) + return try self.mainContext.queryAttributes(from, selectClause, queryClauses) } /** @@ -467,13 +467,13 @@ extension DataStack: FetchableSource, QueryableSource { - parameter clauseChain: a `QueryChainableBuilderType` indicating the properties to fetch and the series of queries for the request. - returns: the result of the the query as specified by the `QueryChainableBuilderType` */ - public func queryAttributes(_ clauseChain: B) -> [[String: Any]]? where B.ResultType == NSDictionary { + public func queryAttributes(_ clauseChain: B) throws -> [[String: Any]] where B.ResultType == NSDictionary { CoreStore.assert( Thread.isMainThread, "Attempted to query from a \(cs_typeName(self)) outside the main thread." ) - return self.mainContext.queryAttributes(clauseChain.from, clauseChain.select, clauseChain.queryClauses) + return try self.mainContext.queryAttributes(clauseChain.from, clauseChain.select, clauseChain.queryClauses) } diff --git a/Sources/FetchableSource.swift b/Sources/FetchableSource.swift index 38bc57d..eaa502c 100644 --- a/Sources/FetchableSource.swift +++ b/Sources/FetchableSource.swift @@ -169,7 +169,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...) throws -> NSManagedObjectID? /** Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -178,7 +178,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]) throws -> NSManagedObjectID? /** Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType` built from a chain of clauses. @@ -192,7 +192,7 @@ public protocol FetchableSource: class { - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType` */ - func fetchObjectID(_ clauseChain: B) -> NSManagedObjectID? + func fetchObjectID(_ clauseChain: B) throws -> NSManagedObjectID? /** Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -201,7 +201,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...) throws -> [NSManagedObjectID] /** Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -210,7 +210,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]) throws -> [NSManagedObjectID] /** Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses. @@ -224,7 +224,7 @@ public protocol FetchableSource: class { - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` */ - func fetchObjectIDs(_ clauseChain: B) -> [NSManagedObjectID]? + func fetchObjectIDs(_ clauseChain: B) throws -> [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/NSManagedObjectContext+ObjectiveC.swift b/Sources/NSManagedObjectContext+ObjectiveC.swift index a2482b6..f0bf381 100644 --- a/Sources/NSManagedObjectContext+ObjectiveC.swift +++ b/Sources/NSManagedObjectContext+ObjectiveC.swift @@ -96,57 +96,45 @@ internal extension NSManagedObjectContext { } @nonobjc - internal func deleteAll(_ from: CSFrom, _ deleteClauses: [CSDeleteClause]) -> Int? { + internal func deleteAll(_ from: CSFrom, _ deleteClauses: [CSDeleteClause]) throws -> Int { let fetchRequest = CoreStoreFetchRequest() - let storeFound = from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self) + try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 0 fetchRequest.resultType = .managedObjectResultType fetchRequest.returnsObjectsAsFaults = true fetchRequest.includesPropertyValues = false deleteClauses.forEach { $0.applyToFetchRequest(fetchRequest) } - - guard storeFound else { - - return nil - } - return self.deleteAll(fetchRequest.dynamicCast()) + + return try self.deleteAll(fetchRequest.dynamicCast()) } @nonobjc - internal func queryValue(_ from: CSFrom, _ selectClause: CSSelect, _ queryClauses: [CSQueryClause]) -> Any? { + internal func queryValue(_ from: CSFrom, _ selectClause: CSSelect, _ queryClauses: [CSQueryClause]) throws -> Any? { let fetchRequest = CoreStoreFetchRequest() - let storeFound = from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self) + try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 0 selectClause.applyToFetchRequest(fetchRequest) queryClauses.forEach { $0.applyToFetchRequest(fetchRequest) } - - guard storeFound else { - - return nil - } - return self.queryValue(selectClause.selectTerms, fetchRequest: fetchRequest.dynamicCast()) + + return try self.queryValue(selectClause.selectTerms, fetchRequest: fetchRequest.dynamicCast()) } @nonobjc - internal func queryAttributes(_ from: CSFrom, _ selectClause: CSSelect, _ queryClauses: [CSQueryClause]) -> [[String: Any]]? { + internal func queryAttributes(_ from: CSFrom, _ selectClause: CSSelect, _ queryClauses: [CSQueryClause]) throws -> [[String: Any]] { let fetchRequest = CoreStoreFetchRequest() - let storeFound = from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self) + try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 0 selectClause.applyToFetchRequest(fetchRequest) queryClauses.forEach { $0.applyToFetchRequest(fetchRequest) } - - guard storeFound else { - - return nil - } - return self.queryAttributes(fetchRequest.dynamicCast()) + + return try self.queryAttributes(fetchRequest.dynamicCast()) } } diff --git a/Sources/NSManagedObjectContext+Querying.swift b/Sources/NSManagedObjectContext+Querying.swift index 57b747e..05ca270 100644 --- a/Sources/NSManagedObjectContext+Querying.swift +++ b/Sources/NSManagedObjectContext+Querying.swift @@ -142,11 +142,11 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) } let entityClass = from.entityClass - return try self.fetchAll(fetchRequest.dynamicCast())?.map(entityClass.cs_fromRaw) + return try self.fetchAll(fetchRequest.dynamicCast()).map(entityClass.cs_fromRaw) } @nonobjc - public func fetchAll(_ clauseChain: B) throw -> [B.ObjectType] { + public func fetchAll(_ clauseChain: B) throws -> [B.ObjectType] { return try self.fetchAll(clauseChain.from, clauseChain.fetchClauses) } @@ -174,42 +174,38 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { } @nonobjc - public func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) -> NSManagedObjectID? { + public func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) throws -> NSManagedObjectID? { - return self.fetchObjectID(from, fetchClauses) + return try self.fetchObjectID(from, fetchClauses) } @nonobjc - public func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? { + public func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) throws -> NSManagedObjectID? { let fetchRequest = CoreStoreFetchRequest() - let storeFound = from.applyToFetchRequest(fetchRequest, context: self) + try from.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 1 fetchRequest.resultType = .managedObjectIDResultType fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) } - - guard storeFound else { - - return nil - } - return self.fetchObjectID(fetchRequest.dynamicCast()) + + return try self.fetchObjectID(fetchRequest.dynamicCast()) } @nonobjc - public func fetchObjectID(_ clauseChain: B) -> NSManagedObjectID? { + public func fetchObjectID(_ clauseChain: B) throws -> NSManagedObjectID? { - return self.fetchObjectID(clauseChain.from, clauseChain.fetchClauses) + return try self.fetchObjectID(clauseChain.from, clauseChain.fetchClauses) } @nonobjc - public func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? { + public func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) throws -> [NSManagedObjectID] { - return self.fetchObjectIDs(from, fetchClauses) + return try self.fetchObjectIDs(from, fetchClauses) } @nonobjc - public func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? { + public func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) throws -> [NSManagedObjectID] { let fetchRequest = CoreStoreFetchRequest() try from.applyToFetchRequest(fetchRequest, context: self) @@ -217,22 +213,18 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { fetchRequest.fetchLimit = 0 fetchRequest.resultType = .managedObjectIDResultType fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) } - - guard storeFound else { - - return nil - } - return self.fetchObjectIDs(fetchRequest.dynamicCast()) + + return try self.fetchObjectIDs(fetchRequest.dynamicCast()) } @nonobjc - public func fetchObjectIDs(_ clauseChain: B) -> [NSManagedObjectID]? { + public func fetchObjectIDs(_ clauseChain: B) throws -> [NSManagedObjectID] { - return self.fetchObjectIDs(clauseChain.from, clauseChain.fetchClauses) + return try self.fetchObjectIDs(clauseChain.from, clauseChain.fetchClauses) } @nonobjc - internal func fetchObjectIDs(_ fetchRequest: NSFetchRequest) -> [NSManagedObjectID]? { + internal func fetchObjectIDs(_ fetchRequest: NSFetchRequest) throws -> [NSManagedObjectID] { var fetchResults: [NSManagedObjectID]? var fetchError: Error? @@ -247,77 +239,70 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { fetchError = error } } - if fetchResults == nil { - - CoreStore.log( - CoreStoreError(fetchError), - "Failed executing fetch request." - ) - return nil + if let fetchResults = fetchResults { + + return fetchResults } - return fetchResults + let coreStoreError = CoreStoreError(fetchError) + CoreStore.log( + coreStoreError, + "Failed executing fetch request." + ) + throw coreStoreError } // MARK: QueryableSource @nonobjc - public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> U? { + public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) throws -> U? { - return self.queryValue(from, selectClause, queryClauses) + return try 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]) throws -> U? { let fetchRequest = CoreStoreFetchRequest() - let storeFound = from.applyToFetchRequest(fetchRequest, context: self) + try from.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 0 selectClause.applyToFetchRequest(fetchRequest) queryClauses.forEach { $0.applyToFetchRequest(fetchRequest) } - - guard storeFound else { - - return nil - } - return self.queryValue(selectClause.selectTerms, fetchRequest: fetchRequest) + + return try self.queryValue(selectClause.selectTerms, fetchRequest: fetchRequest) } @nonobjc - public func queryValue(_ clauseChain: B) -> B.ResultType? where B: QueryChainableBuilderType, B.ResultType: QueryableAttributeType { + public func queryValue(_ clauseChain: B) throws -> B.ResultType? where B: QueryChainableBuilderType, B.ResultType: QueryableAttributeType { - return self.queryValue(clauseChain.from, clauseChain.select, clauseChain.queryClauses) + return try self.queryValue(clauseChain.from, clauseChain.select, clauseChain.queryClauses) } @nonobjc - public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) -> [[String: Any]]? { + public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) throws -> [[String: Any]] { - return self.queryAttributes(from, selectClause, queryClauses) + return try 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]) throws -> [[String: Any]] { let fetchRequest = CoreStoreFetchRequest() - let storeFound = from.applyToFetchRequest(fetchRequest, context: self) + try from.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 0 selectClause.applyToFetchRequest(fetchRequest) queryClauses.forEach { $0.applyToFetchRequest(fetchRequest) } - - guard storeFound else { - - return nil - } - return self.queryAttributes(fetchRequest) + + return try self.queryAttributes(fetchRequest) } - public func queryAttributes(_ clauseChain: B) -> [[String : Any]]? where B : QueryChainableBuilderType, B.ResultType == NSDictionary { + public func queryAttributes(_ clauseChain: B) throws -> [[String : Any]] where B : QueryChainableBuilderType, B.ResultType == NSDictionary { - return self.queryAttributes(clauseChain.from, clauseChain.select, clauseChain.queryClauses) + return try self.queryAttributes(clauseChain.from, clauseChain.select, clauseChain.queryClauses) } @@ -333,22 +318,18 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { // MARK: Deleting @nonobjc - internal func deleteAll(_ from: From, _ deleteClauses: [FetchClause]) -> Int? { + internal func deleteAll(_ from: From, _ deleteClauses: [FetchClause]) throws -> Int { let fetchRequest = CoreStoreFetchRequest() - let storeFound = from.applyToFetchRequest(fetchRequest, context: self) + try from.applyToFetchRequest(fetchRequest, context: self) fetchRequest.fetchLimit = 0 fetchRequest.resultType = .managedObjectResultType fetchRequest.returnsObjectsAsFaults = true fetchRequest.includesPropertyValues = false deleteClauses.forEach { $0.applyToFetchRequest(fetchRequest) } - - guard storeFound else { - - return nil - } - return self.deleteAll(fetchRequest.dynamicCast()) + + return try self.deleteAll(fetchRequest.dynamicCast()) } @@ -384,16 +365,16 @@ internal extension NSManagedObjectContext { fetchError = error } } - if fetchResults == nil { + if let fetchResults = fetchResults { - let coreStoreError = CoreStoreError(fetchError) - CoreStore.log( - coreStoreError, - "Failed executing fetch request." - ) - throw coreStoreError + return fetchResults.first } - return fetchResults?.first + let coreStoreError = CoreStoreError(fetchError) + CoreStore.log( + coreStoreError, + "Failed executing fetch request." + ) + throw coreStoreError } @nonobjc @@ -412,16 +393,16 @@ internal extension NSManagedObjectContext { fetchError = error } } - if fetchResults == nil { + if let fetchResults = fetchResults { - let coreStoreError = CoreStoreError(fetchError) - CoreStore.log( - coreStoreError, - "Failed executing fetch request." - ) - throw coreStoreError + return fetchResults } - return fetchResults + let coreStoreError = CoreStoreError(fetchError) + CoreStore.log( + coreStoreError, + "Failed executing fetch request." + ) + throw coreStoreError } @nonobjc @@ -442,7 +423,7 @@ internal extension NSManagedObjectContext { } if count == NSNotFound { - let coreStoreError = CoreStoreError(fetchError) + let coreStoreError = CoreStoreError(countError) CoreStore.log( coreStoreError, "Failed executing count request." @@ -453,7 +434,7 @@ internal extension NSManagedObjectContext { } @nonobjc - internal func fetchObjectID(_ fetchRequest: NSFetchRequest) -> NSManagedObjectID? { + internal func fetchObjectID(_ fetchRequest: NSFetchRequest) throws -> NSManagedObjectID? { var fetchResults: [NSManagedObjectID]? var fetchError: Error? @@ -468,22 +449,23 @@ internal extension NSManagedObjectContext { fetchError = error } } - if fetchResults == nil { - - CoreStore.log( - CoreStoreError(fetchError), - "Failed executing fetch request." - ) - return nil + if let fetchResults = fetchResults { + + return fetchResults.first } - return fetchResults?.first + let coreStoreError = CoreStoreError(fetchError) + CoreStore.log( + coreStoreError, + "Failed executing fetch request." + ) + throw coreStoreError } // MARK: Querying @nonobjc - internal func queryValue(_ selectTerms: [SelectTerm], fetchRequest: NSFetchRequest) -> U? { + internal func queryValue(_ selectTerms: [SelectTerm], fetchRequest: NSFetchRequest) throws -> U? { var fetchResults: [Any]? var fetchError: Error? @@ -507,16 +489,16 @@ internal extension NSManagedObjectContext { } return nil } - + let coreStoreError = CoreStoreError(fetchError) CoreStore.log( - CoreStoreError(fetchError), + coreStoreError, "Failed executing fetch request." ) - return nil + throw coreStoreError } @nonobjc - internal func queryValue(_ selectTerms: [SelectTerm], fetchRequest: NSFetchRequest) -> Any? { + internal func queryValue(_ selectTerms: [SelectTerm], fetchRequest: NSFetchRequest) throws -> Any? { var fetchResults: [Any]? var fetchError: Error? @@ -540,16 +522,16 @@ internal extension NSManagedObjectContext { } return nil } - + let coreStoreError = CoreStoreError(fetchError) CoreStore.log( - CoreStoreError(fetchError), + coreStoreError, "Failed executing fetch request." ) - return nil + throw coreStoreError } @nonobjc - internal func queryAttributes(_ fetchRequest: NSFetchRequest) -> [[String: Any]]? { + internal func queryAttributes(_ fetchRequest: NSFetchRequest) throws -> [[String: Any]] { var fetchResults: [Any]? var fetchError: Error? @@ -568,19 +550,19 @@ internal extension NSManagedObjectContext { return NSDictionary.cs_fromQueryResultsNativeType(fetchResults) } - + let coreStoreError = CoreStoreError(fetchError) CoreStore.log( - CoreStoreError(fetchError), + coreStoreError, "Failed executing fetch request." ) - return nil + throw coreStoreError } // MARK: Deleting @nonobjc - internal func deleteAll(_ fetchRequest: NSFetchRequest) -> Int? { + internal func deleteAll(_ fetchRequest: NSFetchRequest) throws -> Int { var numberOfDeletedObjects: Int? var fetchError: Error? @@ -603,14 +585,15 @@ internal extension NSManagedObjectContext { } } } - if numberOfDeletedObjects == nil { - - CoreStore.log( - CoreStoreError(fetchError), - "Failed executing fetch request." - ) - return nil + if let numberOfDeletedObjects = numberOfDeletedObjects { + + return numberOfDeletedObjects } - return numberOfDeletedObjects + let coreStoreError = CoreStoreError(fetchError) + CoreStore.log( + coreStoreError, + "Failed executing delete request." + ) + throw coreStoreError } } diff --git a/Sources/QueryableSource.swift b/Sources/QueryableSource.swift index 6dc4650..0ab5abf 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...) throws -> 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]) throws -> U? /** Queries a property value or aggregate as specified by the `QueryChainableBuilderType` built from a chain of clauses. @@ -72,7 +72,7 @@ public protocol QueryableSource: class { - parameter clauseChain: a `QueryChainableBuilderType` indicating the property/aggregate to fetch and the series of queries for the request. - returns: the result of the the query as specified by the `QueryChainableBuilderType` */ - func queryValue(_ clauseChain: B) -> B.ResultType? where B.ResultType: QueryableAttributeType + func queryValue(_ clauseChain: B) throws -> B.ResultType? where B.ResultType: QueryableAttributeType /** 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. @@ -84,7 +84,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...) throws -> [[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. @@ -96,7 +96,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]) throws -> [[String: Any]] /** Queries a dictionary of attribute values or as specified by the `QueryChainableBuilderType` built from a chain of clauses. @@ -121,7 +121,7 @@ public protocol QueryableSource: class { - parameter clauseChain: a `QueryChainableBuilderType` indicating the properties to fetch and the series of queries for the request. - returns: the result of the the query as specified by the `QueryChainableBuilderType` */ - func queryAttributes(_ clauseChain: B) -> [[String: Any]]? where B.ResultType == NSDictionary + func queryAttributes(_ clauseChain: B) throws -> [[String: Any]] where B.ResultType == NSDictionary /** 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. From 6dc48b6af758ca5eb0ff9cac06f40cc1fc2ee5f4 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Thu, 17 Jan 2019 18:43:10 +0900 Subject: [PATCH 3/4] Add docs for new throwing methods --- CoreStoreTests/DynamicModelTests.swift | 3 ++ Sources/BaseDataTransaction+Querying.swift | 57 +++++++++++++++------- Sources/CoreStore+Querying.swift | 57 +++++++++++++++------- Sources/DataStack+Querying.swift | 57 +++++++++++++++------- Sources/FetchableSource.swift | 45 +++++++++++------ Sources/QueryableSource.swift | 12 +++-- Sources/Select.swift | 6 +++ 7 files changed, 165 insertions(+), 72 deletions(-) diff --git a/CoreStoreTests/DynamicModelTests.swift b/CoreStoreTests/DynamicModelTests.swift index 1cb66c9..cc0ce3a 100644 --- a/CoreStoreTests/DynamicModelTests.swift +++ b/CoreStoreTests/DynamicModelTests.swift @@ -266,6 +266,9 @@ class DynamicModelTests: BaseTestDataTestCase { let p3 = Where({ $0.age == 10 }) XCTAssertEqual(p3.predicate, NSPredicate(format: "%K == %d", "age", 10)) + + let totalAge = try transaction.queryValue(From().select(Int.self, .sum(\Dog.age))) + XCTAssertEqual(totalAge, 1) _ = try transaction.fetchAll( From() diff --git a/Sources/BaseDataTransaction+Querying.swift b/Sources/BaseDataTransaction+Querying.swift index 82c9e02..a3be030 100644 --- a/Sources/BaseDataTransaction+Querying.swift +++ b/Sources/BaseDataTransaction+Querying.swift @@ -136,7 +136,8 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s, or `nil` if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchOne(_ from: From, _ fetchClauses: FetchClause...) throws -> D? { @@ -152,7 +153,8 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s, or `nil` if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) throws -> D? { @@ -173,7 +175,8 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { ) ``` - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - - returns: the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType` + - returns: the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType`, or `nil` if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchOne(_ clauseChain: B) throws -> B.ObjectType? { @@ -189,7 +192,8 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter from: a `From` clause indicating the entity type - 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 + - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s, or an empty array if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchAll(_ from: From, _ fetchClauses: FetchClause...) throws -> [D] { @@ -205,7 +209,8 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter from: a `From` clause indicating the entity type - 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 + - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s, or an empty array if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) throws -> [D] { @@ -226,7 +231,8 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { ) ``` - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - - returns: all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType` + - returns: all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType`, or an empty array if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchAll(_ clauseChain: B) throws -> [B.ObjectType] { @@ -242,7 +248,8 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the number of `DynamicObject`s that satisfy the specified `FetchClause`s + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchCount(_ from: From, _ fetchClauses: FetchClause...) throws -> Int { @@ -258,7 +265,8 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the number of `DynamicObject`s that satisfy the specified `FetchClause`s + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) throws -> Int { @@ -279,7 +287,8 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { ) ``` - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - - returns: the number `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` + - returns: the number of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchCount(_ clauseChain: B) throws -> Int { @@ -295,7 +304,8 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s, or `nil` if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) throws -> NSManagedObjectID? { @@ -311,7 +321,8 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s, or `nil` if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) throws -> NSManagedObjectID? { @@ -332,7 +343,8 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { ) ``` - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType` + - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType`, or `nil` if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchObjectID(_ clauseChain: B) throws -> NSManagedObjectID? { @@ -348,7 +360,8 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s, or an empty array if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) throws -> [NSManagedObjectID] { @@ -364,7 +377,8 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s, or an empty array if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) throws -> [NSManagedObjectID] { @@ -385,7 +399,8 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { ) ``` - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` + - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`, or an empty array if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchObjectIDs(_ clauseChain: B) throws -> [NSManagedObjectID] { @@ -407,7 +422,8 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter from: a `From` clause indicating the entity type - parameter selectClause: a `Select` clause indicating the properties to fetch, and with the generic type indicating the return type. - 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. + - returns: the result of the the query, or `nil` if no match was found. The type of the return value is specified by the generic type of the `Select` parameter. + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) throws -> U? { @@ -426,7 +442,8 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter from: a `From` clause indicating the entity type - parameter selectClause: a `Select` clause indicating the properties to fetch, and with the generic type indicating the return type. - 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. + - returns: the result of the the query, or `nil` if no match was found. The type of the return value is specified by the generic type of the `Select` parameter. + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) throws -> U? { @@ -449,7 +466,8 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { ) ``` - parameter clauseChain: a `QueryChainableBuilderType` indicating the property/aggregate to fetch and the series of queries for the request. - - returns: the result of the the query as specified by the `QueryChainableBuilderType` + - returns: the result of the the query as specified by the `QueryChainableBuilderType`, or `nil` if no match was found. + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func queryValue(_ clauseChain: B) throws -> B.ResultType? where B.ResultType: QueryableAttributeType { @@ -469,6 +487,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter selectClause: a `Select` clause indicating the properties to fetch, and with the generic type indicating the return type. - 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. + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) throws -> [[String: Any]] { @@ -488,6 +507,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { - parameter selectClause: a `Select` clause indicating the properties to fetch, and with the generic type indicating the return type. - 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. + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) throws -> [[String: Any]] { @@ -520,6 +540,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource { ``` - parameter clauseChain: a `QueryChainableBuilderType` indicating the properties to fetch and the series of queries for the request. - returns: the result of the the query as specified by the `QueryChainableBuilderType` + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func queryAttributes(_ clauseChain: B) throws -> [[String: Any]] where B.ResultType == NSDictionary { diff --git a/Sources/CoreStore+Querying.swift b/Sources/CoreStore+Querying.swift index 49fe4ae..1687b9f 100644 --- a/Sources/CoreStore+Querying.swift +++ b/Sources/CoreStore+Querying.swift @@ -80,7 +80,8 @@ public extension CoreStore { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s, or `nil` if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public static func fetchOne(_ from: From, _ fetchClauses: FetchClause...) throws -> D? { @@ -92,7 +93,8 @@ public extension CoreStore { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s, or `nil` if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public static func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) throws -> D? { @@ -109,7 +111,8 @@ public extension CoreStore { ) ``` - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - - returns: the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType` + - returns: the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType`, or `nil` if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public static func fetchOne(_ clauseChain: B) throws -> B.ObjectType? { @@ -121,7 +124,8 @@ public extension CoreStore { - parameter from: a `From` clause indicating the entity type - 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 + - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s, or an empty array if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public static func fetchAll(_ from: From, _ fetchClauses: FetchClause...) throws -> [D] { @@ -133,7 +137,8 @@ public extension CoreStore { - parameter from: a `From` clause indicating the entity type - 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 + - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s, or an empty array if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public static func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) throws -> [D] { @@ -150,7 +155,8 @@ public extension CoreStore { ) ``` - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - - returns: all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType` + - returns: all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType`, or an empty array if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public static func fetchAll(_ clauseChain: B) throws -> [B.ObjectType] { @@ -162,7 +168,8 @@ public extension CoreStore { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the number of `DynamicObject`s that satisfy the specified `FetchClause`s + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public static func fetchCount(_ from: From, _ fetchClauses: FetchClause...) throws -> Int { @@ -174,7 +181,8 @@ public extension CoreStore { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the number of `DynamicObject`s that satisfy the specified `FetchClause`s + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public static func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) throws -> Int { @@ -191,7 +199,8 @@ public extension CoreStore { ) ``` - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - - returns: the number `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` + - returns: the number of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public static func fetchCount(_ clauseChain: B) throws -> Int { @@ -203,7 +212,8 @@ public extension CoreStore { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s, or `nil` if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public static func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) throws -> NSManagedObjectID? { @@ -215,7 +225,8 @@ public extension CoreStore { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s, or `nil` if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public static func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) throws -> NSManagedObjectID? { @@ -232,7 +243,8 @@ public extension CoreStore { ) ``` - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType` + - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType`, or `nil` if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public static func fetchObjectID(_ clauseChain: B) throws -> NSManagedObjectID? { @@ -244,7 +256,8 @@ public extension CoreStore { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s, or an empty array if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public static func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) throws -> [NSManagedObjectID] { @@ -256,7 +269,8 @@ public extension CoreStore { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s, or an empty array if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public static func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) throws -> [NSManagedObjectID] { @@ -273,7 +287,8 @@ public extension CoreStore { ) ``` - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` + - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`, or an empty array if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public static func fetchObjectIDs(_ clauseChain: B) throws -> [NSManagedObjectID] { @@ -288,7 +303,8 @@ public extension CoreStore { - parameter from: a `From` clause indicating the entity type - parameter selectClause: a `Select` clause indicating the properties to fetch, and with the generic type indicating the return type. - 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. + - returns: the result of the the query, or `nil` if no match was found. The type of the return value is specified by the generic type of the `Select` parameter. + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public static func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) throws -> U? { @@ -303,7 +319,8 @@ public extension CoreStore { - parameter from: a `From` clause indicating the entity type - parameter selectClause: a `Select` clause indicating the properties to fetch, and with the generic type indicating the return type. - 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. + - returns: the result of the the query, or `nil` if no match was found. The type of the return value is specified by the generic type of the `Select` parameter. + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public static func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) throws -> U? { @@ -322,7 +339,8 @@ public extension CoreStore { ) ``` - parameter clauseChain: a `QueryChainableBuilderType` indicating the property/aggregate to fetch and the series of queries for the request. - - returns: the result of the the query as specified by the `QueryChainableBuilderType` + - returns: the result of the the query as specified by the `QueryChainableBuilderType`, or `nil` if no match was found. + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public static func queryValue(_ clauseChain: B) throws -> B.ResultType? where B.ResultType: QueryableAttributeType { @@ -338,6 +356,7 @@ public extension CoreStore { - parameter selectClause: a `Select` clause indicating the properties to fetch, and with the generic type indicating the return type. - 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. + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public static func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) throws -> [[String: Any]] { @@ -353,6 +372,7 @@ public extension CoreStore { - parameter selectClause: a `Select` clause indicating the properties to fetch, and with the generic type indicating the return type. - 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. + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public static func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) throws -> [[String: Any]] { @@ -381,6 +401,7 @@ public extension CoreStore { ``` - parameter clauseChain: a `QueryChainableBuilderType` indicating the properties to fetch and the series of queries for the request. - returns: the result of the the query as specified by the `QueryChainableBuilderType` + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public static func queryAttributes(_ clauseChain: B) throws -> [[String: Any]] where B.ResultType == NSDictionary { diff --git a/Sources/DataStack+Querying.swift b/Sources/DataStack+Querying.swift index 411ca10..31495c3 100644 --- a/Sources/DataStack+Querying.swift +++ b/Sources/DataStack+Querying.swift @@ -82,7 +82,8 @@ extension DataStack: FetchableSource, QueryableSource { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s, or `nil` if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchOne(_ from: From, _ fetchClauses: FetchClause...) throws -> D? { @@ -98,7 +99,8 @@ extension DataStack: FetchableSource, QueryableSource { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s, or `nil` if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) throws -> D? { @@ -119,7 +121,8 @@ extension DataStack: FetchableSource, QueryableSource { ) ``` - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - - returns: the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType` + - returns: the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType`, or `nil` if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchOne(_ clauseChain: B) throws -> B.ObjectType? { @@ -135,7 +138,8 @@ extension DataStack: FetchableSource, QueryableSource { - parameter from: a `From` clause indicating the entity type - 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 + - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s, or an empty array if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchAll(_ from: From, _ fetchClauses: FetchClause...) throws -> [D] { @@ -151,7 +155,8 @@ extension DataStack: FetchableSource, QueryableSource { - parameter from: a `From` clause indicating the entity type - 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 + - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s, or an empty array if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) throws -> [D] { @@ -172,7 +177,8 @@ extension DataStack: FetchableSource, QueryableSource { ) ``` - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - - returns: all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType` + - returns: all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType`, or an empty array if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchAll(_ clauseChain: B) throws -> [B.ObjectType] { @@ -188,7 +194,8 @@ extension DataStack: FetchableSource, QueryableSource { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the number of `DynamicObject`s that satisfy the specified `FetchClause`s + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchCount(_ from: From, _ fetchClauses: FetchClause...) throws -> Int { @@ -204,7 +211,8 @@ extension DataStack: FetchableSource, QueryableSource { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the number of `DynamicObject`s that satisfy the specified `FetchClause`s + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) throws -> Int { @@ -225,7 +233,8 @@ extension DataStack: FetchableSource, QueryableSource { ) ``` - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - - returns: the number `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` + - returns: the number of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchCount(_ clauseChain: B) throws -> Int { @@ -241,7 +250,8 @@ extension DataStack: FetchableSource, QueryableSource { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s, or `nil` if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) throws -> NSManagedObjectID? { @@ -257,7 +267,8 @@ extension DataStack: FetchableSource, QueryableSource { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s, or `nil` if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) throws -> NSManagedObjectID? { @@ -278,7 +289,8 @@ extension DataStack: FetchableSource, QueryableSource { ) ``` - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType` + - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType`, or `nil` if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchObjectID(_ clauseChain: B) throws -> NSManagedObjectID? { @@ -294,7 +306,8 @@ extension DataStack: FetchableSource, QueryableSource { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s, or an empty array if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) throws -> [NSManagedObjectID] { @@ -310,7 +323,8 @@ extension DataStack: FetchableSource, QueryableSource { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s, or an empty array if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) throws -> [NSManagedObjectID] { @@ -331,7 +345,8 @@ extension DataStack: FetchableSource, QueryableSource { ) ``` - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` + - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`, or an empty array if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func fetchObjectIDs(_ clauseChain: B) throws -> [NSManagedObjectID] { @@ -353,7 +368,8 @@ extension DataStack: FetchableSource, QueryableSource { - parameter from: a `From` clause indicating the entity type - parameter selectClause: a `Select` clause indicating the properties to fetch, and with the generic type indicating the return type. - 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. + - returns: the result of the the query, or `nil` if no match was found. The type of the return value is specified by the generic type of the `Select` parameter. + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) throws -> U? { @@ -372,7 +388,8 @@ extension DataStack: FetchableSource, QueryableSource { - parameter from: a `From` clause indicating the entity type - parameter selectClause: a `Select` clause indicating the properties to fetch, and with the generic type indicating the return type. - 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. + - returns: the result of the the query, or `nil` if no match was found. The type of the return value is specified by the generic type of the `Select` parameter. + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) throws -> U? { @@ -395,7 +412,8 @@ extension DataStack: FetchableSource, QueryableSource { ) ``` - parameter clauseChain: a `QueryChainableBuilderType` indicating the property/aggregate to fetch and the series of queries for the request. - - returns: the result of the the query as specified by the `QueryChainableBuilderType` + - returns: the result of the the query as specified by the `QueryChainableBuilderType`, or `nil` if no match was found. + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func queryValue(_ clauseChain: B) throws -> B.ResultType? where B.ResultType: QueryableAttributeType { @@ -415,6 +433,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter selectClause: a `Select` clause indicating the properties to fetch, and with the generic type indicating the return type. - 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. + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) throws -> [[String: Any]] { @@ -434,6 +453,7 @@ extension DataStack: FetchableSource, QueryableSource { - parameter selectClause: a `Select` clause indicating the properties to fetch, and with the generic type indicating the return type. - 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. + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) throws -> [[String: Any]] { @@ -466,6 +486,7 @@ extension DataStack: FetchableSource, QueryableSource { ``` - parameter clauseChain: a `QueryChainableBuilderType` indicating the properties to fetch and the series of queries for the request. - returns: the result of the the query as specified by the `QueryChainableBuilderType` + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ public func queryAttributes(_ clauseChain: B) throws -> [[String: Any]] where B.ResultType == NSDictionary { diff --git a/Sources/FetchableSource.swift b/Sources/FetchableSource.swift index eaa502c..1a24b66 100644 --- a/Sources/FetchableSource.swift +++ b/Sources/FetchableSource.swift @@ -71,7 +71,8 @@ public protocol FetchableSource: class { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s, or `nil` if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ func fetchOne(_ from: From, _ fetchClauses: FetchClause...) throws -> D? @@ -80,7 +81,8 @@ public protocol FetchableSource: class { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the first `DynamicObject` instance that satisfies the specified `FetchClause`s, or `nil` if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ func fetchOne(_ from: From, _ fetchClauses: [FetchClause]) throws -> D? @@ -94,7 +96,8 @@ public protocol FetchableSource: class { ) ``` - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - - returns: the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType` + - returns: the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType`, or `nil` if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ func fetchOne(_ clauseChain: B) throws -> B.ObjectType? @@ -103,7 +106,8 @@ public protocol FetchableSource: class { - parameter from: a `From` clause indicating the entity type - 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 + - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s, or an empty array if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ func fetchAll(_ from: From, _ fetchClauses: FetchClause...) throws -> [D] @@ -112,7 +116,8 @@ public protocol FetchableSource: class { - parameter from: a `From` clause indicating the entity type - 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 + - returns: all `DynamicObject` instances that satisfy the specified `FetchClause`s, or an empty array if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ func fetchAll(_ from: From, _ fetchClauses: [FetchClause]) throws -> [D] @@ -126,7 +131,8 @@ public protocol FetchableSource: class { ) ``` - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - - returns: all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType` + - returns: all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType`, or an empty array if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ func fetchAll(_ clauseChain: B) throws -> [B.ObjectType] @@ -135,7 +141,8 @@ public protocol FetchableSource: class { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the number of `DynamicObject`s that satisfy the specified `FetchClause`s + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ func fetchCount(_ from: From, _ fetchClauses: FetchClause...) throws -> Int @@ -144,7 +151,8 @@ public protocol FetchableSource: class { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the number of `DynamicObject`s that satisfy the specified `FetchClause`s + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ func fetchCount(_ from: From, _ fetchClauses: [FetchClause]) throws -> Int @@ -158,7 +166,8 @@ public protocol FetchableSource: class { ) ``` - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - - returns: the number `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` + - returns: the number of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ func fetchCount(_ clauseChain: B) throws -> Int @@ -167,7 +176,8 @@ public protocol FetchableSource: class { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s, or `nil` if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ func fetchObjectID(_ from: From, _ fetchClauses: FetchClause...) throws -> NSManagedObjectID? @@ -176,7 +186,8 @@ public protocol FetchableSource: class { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s, or `nil` if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ func fetchObjectID(_ from: From, _ fetchClauses: [FetchClause]) throws -> NSManagedObjectID? @@ -190,7 +201,8 @@ public protocol FetchableSource: class { ) ``` - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType` + - returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType`, or `nil` if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ func fetchObjectID(_ clauseChain: B) throws -> NSManagedObjectID? @@ -199,7 +211,8 @@ public protocol FetchableSource: class { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s, or an empty array if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ func fetchObjectIDs(_ from: From, _ fetchClauses: FetchClause...) throws -> [NSManagedObjectID] @@ -208,7 +221,8 @@ public protocol FetchableSource: class { - parameter from: a `From` clause indicating the entity type - 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 + - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s, or an empty array if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ func fetchObjectIDs(_ from: From, _ fetchClauses: [FetchClause]) throws -> [NSManagedObjectID] @@ -222,7 +236,8 @@ public protocol FetchableSource: class { ) ``` - parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses - - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` + - returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`, or an empty array if no match was found + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ func fetchObjectIDs(_ clauseChain: B) throws -> [NSManagedObjectID] diff --git a/Sources/QueryableSource.swift b/Sources/QueryableSource.swift index 0ab5abf..42b2293 100644 --- a/Sources/QueryableSource.swift +++ b/Sources/QueryableSource.swift @@ -42,7 +42,8 @@ public protocol QueryableSource: class { - parameter from: a `From` clause indicating the entity type - parameter selectClause: a `Select` clause indicating the properties to fetch, and with the generic type indicating the return type. - 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. + - returns: the result of the the query, or `nil` if no match was found. The type of the return value is specified by the generic type of the `Select` parameter. + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) throws -> U? @@ -54,7 +55,8 @@ public protocol QueryableSource: class { - parameter from: a `From` clause indicating the entity type - parameter selectClause: a `Select` clause indicating the properties to fetch, and with the generic type indicating the return type. - 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. + - returns: the result of the the query, or `nil` if no match was found. The type of the return value is specified by the generic type of the `Select` parameter. + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ func queryValue(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) throws -> U? @@ -70,7 +72,8 @@ public protocol QueryableSource: class { ) ``` - parameter clauseChain: a `QueryChainableBuilderType` indicating the property/aggregate to fetch and the series of queries for the request. - - returns: the result of the the query as specified by the `QueryChainableBuilderType` + - returns: the result of the the query as specified by the `QueryChainableBuilderType`, or `nil` if no match was found. + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ func queryValue(_ clauseChain: B) throws -> B.ResultType? where B.ResultType: QueryableAttributeType @@ -83,6 +86,7 @@ public protocol QueryableSource: class { - parameter selectClause: a `Select` clause indicating the properties to fetch, and with the generic type indicating the return type. - 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. + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: QueryClause...) throws -> [[String: Any]] @@ -95,6 +99,7 @@ public protocol QueryableSource: class { - parameter selectClause: a `Select` clause indicating the properties to fetch, and with the generic type indicating the return type. - 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. + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ func queryAttributes(_ from: From, _ selectClause: Select, _ queryClauses: [QueryClause]) throws -> [[String: Any]] @@ -120,6 +125,7 @@ public protocol QueryableSource: class { ``` - parameter clauseChain: a `QueryChainableBuilderType` indicating the properties to fetch and the series of queries for the request. - returns: the result of the the query as specified by the `QueryChainableBuilderType` + - throws: a `CoreStoreError` value indicating the failure if the specified entity could not be found in any store's schema. */ func queryAttributes(_ clauseChain: B) throws -> [[String: Any]] where B.ResultType == NSDictionary diff --git a/Sources/Select.swift b/Sources/Select.swift index b3cb8b1..50c1a02 100644 --- a/Sources/Select.swift +++ b/Sources/Select.swift @@ -298,6 +298,9 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable { } } + +// MARK: - SelectTerm where D: NSManagedObject + extension SelectTerm where D: NSManagedObject { /** @@ -366,6 +369,9 @@ extension SelectTerm where D: NSManagedObject { } } + +// MARK: - SelectTerm where D: CoreStoreObject + extension SelectTerm where D: CoreStoreObject { /** From 84f3740ea1f44aafda67b28f8a8c362a62b667e5 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Fri, 18 Jan 2019 17:30:54 +0900 Subject: [PATCH 4/4] fix unit test warnings --- CoreStoreTests/TransactionTests.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CoreStoreTests/TransactionTests.swift b/CoreStoreTests/TransactionTests.swift index 9b45137..a6c4a05 100644 --- a/CoreStoreTests/TransactionTests.swift +++ b/CoreStoreTests/TransactionTests.swift @@ -739,8 +739,11 @@ final class TransactionTests: BaseTestCase { do { - XCTAssertEqual(try stack.fetchCount(From("Config1")), 0) - XCTAssertEqual(try stack.fetchCount(From(nil)), 0) + let configCount = try stack.fetchCount(From("Config1")) + XCTAssertEqual(configCount, 0) + + let defaultCount = try stack.fetchCount(From(nil)) + XCTAssertEqual(defaultCount, 0) deleteExpectation.fulfill() }