mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-04-01 07:03:06 +02:00
WIP: make fetching methods throwable
This commit is contained in:
@@ -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.
|
- 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
|
||||||
*/
|
*/
|
||||||
public func fetchOne<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> D? {
|
public func fetchOne<D>(_ from: From<D>, _ fetchClauses: FetchClause...) throws -> D? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
"Attempted to fetch from a \(cs_typeName(self)) outside its designated queue."
|
"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.
|
- 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
|
||||||
*/
|
*/
|
||||||
public func fetchOne<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> D? {
|
public func fetchOne<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) throws -> D? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
"Attempted to fetch from a \(cs_typeName(self)) outside its designated queue."
|
"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
|
- 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`
|
||||||
*/
|
*/
|
||||||
public func fetchOne<B: FetchChainableBuilderType>(_ clauseChain: B) -> B.ObjectType? {
|
public func fetchOne<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> B.ObjectType? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
"Attempted to fetch from a \(cs_typeName(self)) outside its designated queue."
|
"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.
|
- 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
|
||||||
*/
|
*/
|
||||||
public func fetchAll<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> [D]? {
|
public func fetchAll<D>(_ from: From<D>, _ fetchClauses: FetchClause...) throws -> [D] {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
"Attempted to fetch from a \(cs_typeName(self)) outside its designated queue."
|
"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.
|
- 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
|
||||||
*/
|
*/
|
||||||
public func fetchAll<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> [D]? {
|
public func fetchAll<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) throws -> [D] {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
"Attempted to fetch from a \(cs_typeName(self)) outside its designated queue."
|
"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
|
- 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`
|
||||||
*/
|
*/
|
||||||
public func fetchAll<B: FetchChainableBuilderType>(_ clauseChain: B) -> [B.ObjectType]? {
|
public func fetchAll<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> [B.ObjectType] {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
"Attempted to fetch from a \(cs_typeName(self)) outside its designated queue."
|
"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.
|
- 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 `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public func fetchCount<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> Int? {
|
public func fetchCount<D>(_ from: From<D>, _ fetchClauses: FetchClause...) throws -> Int {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
"Attempted to fetch from a \(cs_typeName(self)) outside its designated queue."
|
"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.
|
- 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 `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public func fetchCount<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> Int? {
|
public func fetchCount<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) throws -> Int {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
"Attempted to fetch from a \(cs_typeName(self)) outside its designated queue."
|
"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
|
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
|
||||||
- returns: the number `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
|
- returns: the number `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
|
||||||
*/
|
*/
|
||||||
public func fetchCount<B: FetchChainableBuilderType>(_ clauseChain: B) -> Int? {
|
public func fetchCount<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> Int {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
"Attempted to fetch from a \(cs_typeName(self)) outside its designated queue."
|
"Attempted to fetch from a \(cs_typeName(self)) outside its designated queue."
|
||||||
)
|
)
|
||||||
return self.context.fetchCount(clauseChain)
|
return try self.context.fetchCount(clauseChain)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -247,6 +247,14 @@ extension CoreStoreError: CoreStoreSwiftType, _ObjectiveCBridgeableError {
|
|||||||
|
|
||||||
case .userCancelled:
|
case .userCancelled:
|
||||||
self = .userCancelled
|
self = .userCancelled
|
||||||
|
|
||||||
|
case .persistentStoreNotFound:
|
||||||
|
guard let entity = info["entity"] as? DynamicObject.Type else {
|
||||||
|
|
||||||
|
self = .unknown
|
||||||
|
return
|
||||||
|
}
|
||||||
|
self = .persistentStoreNotFound(entity: entity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ public final class CSListMonitor: NSObject {
|
|||||||
@objc
|
@objc
|
||||||
public func hasObjectsInSection(_ section: Int) -> Bool {
|
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
|
@objc
|
||||||
public func objectsInSection(_ section: Int) -> [NSManagedObject] {
|
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
|
@objc
|
||||||
public func objectsInSafeSection(safeSectionIndex section: Int) -> [NSManagedObject]? {
|
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
|
@objc
|
||||||
public func numberOfObjectsInSection(_ section: Int) -> Int {
|
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? {
|
public func numberOfObjectsInSafeSection(safeSectionIndex section: Int) -> NSNumber? {
|
||||||
|
|
||||||
return self.bridgeToSwift
|
return self.bridgeToSwift
|
||||||
.numberOfObjectsInSection(safeSectionIndex: section)
|
.numberOfObjects(safelyIn: section)
|
||||||
.flatMap { NSNumber(value: $0) }
|
.flatMap { NSNumber(value: $0) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,7 +227,7 @@ public final class CSListMonitor: NSObject {
|
|||||||
@objc
|
@objc
|
||||||
public func sectionInfoAtIndex(_ section: Int) -> NSFetchedResultsSectionInfo {
|
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
|
@objc
|
||||||
public func sectionInfoAtSafeSectionIndex(safeSectionIndex section: Int) -> NSFetchedResultsSectionInfo? {
|
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
|
@objc
|
||||||
public func targetSectionForSectionIndexTitle(title: String, index: Int) -> Int {
|
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? {
|
public func indexOf(_ object: NSManagedObject) -> NSNumber? {
|
||||||
|
|
||||||
return self.bridgeToSwift
|
return self.bridgeToSwift
|
||||||
.indexOf(object)
|
.index(of: object)
|
||||||
.flatMap { NSNumber(value: $0) }
|
.flatMap { NSNumber(value: $0) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,7 +300,7 @@ public final class CSListMonitor: NSObject {
|
|||||||
@objc
|
@objc
|
||||||
public func indexPathOf(_ object: NSManagedObject) -> IndexPath? {
|
public func indexPathOf(_ object: NSManagedObject) -> IndexPath? {
|
||||||
|
|
||||||
return self.bridgeToSwift.indexPathOf(object)
|
return self.bridgeToSwift.indexPath(of: object)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ public extension CoreStore {
|
|||||||
|
|
||||||
```
|
```
|
||||||
CoreStore.monitorList(
|
CoreStore.monitorList(
|
||||||
{ (monitor) in
|
createAsynchronously: { (monitor) in
|
||||||
self.monitor = monitor
|
self.monitor = monitor
|
||||||
},
|
},
|
||||||
From<MyPersonEntity>()
|
From<MyPersonEntity>()
|
||||||
@@ -123,7 +123,6 @@ public extension CoreStore {
|
|||||||
```
|
```
|
||||||
- parameter createAsynchronously: the closure that receives the created `ListMonitor` instance
|
- parameter createAsynchronously: the closure that receives the created `ListMonitor` instance
|
||||||
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
|
- 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<B: FetchChainableBuilderType>(createAsynchronously: @escaping (ListMonitor<B.ObjectType>) -> Void, _ clauseChain: B) {
|
public static func monitorList<B: FetchChainableBuilderType>(createAsynchronously: @escaping (ListMonitor<B.ObjectType>) -> 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.
|
Asynchronously creates a `ListMonitor` for a sectioned list of `DynamicObject`s that satisfy the specified `SectionMonitorBuilderType` built from a chain of clauses.
|
||||||
```
|
```
|
||||||
CoreStore.monitorSectionedList(
|
CoreStore.monitorSectionedList(
|
||||||
{ (monitor) in
|
createAsynchronously: { (monitor) in
|
||||||
self.monitor = monitor
|
self.monitor = monitor
|
||||||
},
|
},
|
||||||
From<MyPersonEntity>()
|
From<MyPersonEntity>()
|
||||||
@@ -221,8 +220,8 @@ public extension CoreStore {
|
|||||||
.orderBy(.ascending(\.age))
|
.orderBy(.ascending(\.age))
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
- parameter createAsynchronously: the closure that receives the created `ListMonitor` instance
|
||||||
- parameter clauseChain: a `SectionMonitorBuilderType` built from a chain of clauses
|
- 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<B: SectionMonitorBuilderType>(createAsynchronously: @escaping (ListMonitor<B.ObjectType>) -> Void, _ clauseChain: B) {
|
public static func monitorSectionedList<B: SectionMonitorBuilderType>(createAsynchronously: @escaping (ListMonitor<B.ObjectType>) -> Void, _ clauseChain: B) {
|
||||||
|
|
||||||
|
|||||||
@@ -82,9 +82,9 @@ public extension CoreStore {
|
|||||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
- 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
|
||||||
*/
|
*/
|
||||||
public static func fetchOne<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> D? {
|
public static func fetchOne<D>(_ from: From<D>, _ 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.
|
- 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
|
||||||
*/
|
*/
|
||||||
public static func fetchOne<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> D? {
|
public static func fetchOne<D>(_ from: From<D>, _ 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
|
- 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`
|
||||||
*/
|
*/
|
||||||
public static func fetchOne<B: FetchChainableBuilderType>(_ clauseChain: B) -> B.ObjectType? {
|
public static func fetchOne<B: FetchChainableBuilderType>(_ 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.
|
- 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
|
||||||
*/
|
*/
|
||||||
public static func fetchAll<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> [D]? {
|
public static func fetchAll<D>(_ from: From<D>, _ 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.
|
- 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
|
||||||
*/
|
*/
|
||||||
public static func fetchAll<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> [D]? {
|
public static func fetchAll<D>(_ from: From<D>, _ 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
|
- 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`
|
||||||
*/
|
*/
|
||||||
public static func fetchAll<B: FetchChainableBuilderType>(_ clauseChain: B) -> [B.ObjectType]? {
|
public static func fetchAll<B: FetchChainableBuilderType>(_ 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.
|
- 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 `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public static func fetchCount<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> Int? {
|
public static func fetchCount<D>(_ from: From<D>, _ 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.
|
- 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 `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public static func fetchCount<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> Int? {
|
public static func fetchCount<D>(_ from: From<D>, _ 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
|
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
|
||||||
- returns: the number `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
|
- returns: the number `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
|
||||||
*/
|
*/
|
||||||
public static func fetchCount<B: FetchChainableBuilderType>(_ clauseChain: B) -> Int? {
|
public static func fetchCount<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> Int {
|
||||||
|
|
||||||
return self.defaultStack.fetchCount(clauseChain)
|
return try self.defaultStack.fetchCount(clauseChain)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -74,6 +74,11 @@ public enum CoreStoreError: Error, CustomNSError, Hashable {
|
|||||||
*/
|
*/
|
||||||
case userCancelled
|
case userCancelled
|
||||||
|
|
||||||
|
/**
|
||||||
|
Attempted to perform a fetch but could not find any related persistent store.
|
||||||
|
*/
|
||||||
|
case persistentStoreNotFound(entity: DynamicObject.Type)
|
||||||
|
|
||||||
|
|
||||||
// MARK: CustomNSError
|
// MARK: CustomNSError
|
||||||
|
|
||||||
@@ -109,6 +114,9 @@ public enum CoreStoreError: Error, CustomNSError, Hashable {
|
|||||||
|
|
||||||
case .userCancelled:
|
case .userCancelled:
|
||||||
return CoreStoreErrorCode.userCancelled.rawValue
|
return CoreStoreErrorCode.userCancelled.rawValue
|
||||||
|
|
||||||
|
case .persistentStoreNotFound:
|
||||||
|
return CoreStoreErrorCode.persistentStoreNotFound.rawValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,6 +162,11 @@ public enum CoreStoreError: Error, CustomNSError, Hashable {
|
|||||||
|
|
||||||
case .userCancelled:
|
case .userCancelled:
|
||||||
return [:]
|
return [:]
|
||||||
|
|
||||||
|
case .persistentStoreNotFound(let entity):
|
||||||
|
return [
|
||||||
|
"entity": entity
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,6 +209,9 @@ public enum CoreStoreError: Error, CustomNSError, Hashable {
|
|||||||
case (.userCancelled, .userCancelled):
|
case (.userCancelled, .userCancelled):
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
case (.persistentStoreNotFound(let entity1), .persistentStoreNotFound(let entity2)):
|
||||||
|
return entity1 == entity2
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -233,6 +249,9 @@ public enum CoreStoreError: Error, CustomNSError, Hashable {
|
|||||||
case .userError(let error):
|
case .userError(let error):
|
||||||
hasher.combine(error as NSError)
|
hasher.combine(error as NSError)
|
||||||
|
|
||||||
|
case .persistentStoreNotFound(let entity):
|
||||||
|
hasher.combine(ObjectIdentifier(entity))
|
||||||
|
|
||||||
case .userCancelled:
|
case .userCancelled:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -303,6 +322,11 @@ public enum CoreStoreErrorCode: Int {
|
|||||||
The transaction was cancelled by the user.
|
The transaction was cancelled by the user.
|
||||||
*/
|
*/
|
||||||
case userCancelled
|
case userCancelled
|
||||||
|
|
||||||
|
/**
|
||||||
|
Attempted to perform a fetch but could not find any related persistent store.
|
||||||
|
*/
|
||||||
|
case persistentStoreNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll
|
|||||||
|
|
||||||
self.reapplyAffectedStores = { fetchRequest, context in
|
self.reapplyAffectedStores = { fetchRequest, context in
|
||||||
|
|
||||||
return from.applyAffectedStoresForFetchedRequest(fetchRequest, context: context)
|
return try rom.applyAffectedStoresForFetchedRequest(fetchRequest, context: context)
|
||||||
}
|
}
|
||||||
|
|
||||||
super.init(
|
super.init(
|
||||||
@@ -72,13 +72,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll
|
|||||||
@nonobjc
|
@nonobjc
|
||||||
internal func performFetchFromSpecifiedStores() throws {
|
internal func performFetchFromSpecifiedStores() throws {
|
||||||
|
|
||||||
if !self.reapplyAffectedStores(self.fetchRequest, self.managedObjectContext) {
|
try 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.performFetch()
|
try self.performFetch()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,5 +91,5 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll
|
|||||||
// MARK: Private
|
// MARK: Private
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
private let reapplyAffectedStores: (_ fetchRequest: NSFetchRequest<NSManagedObject>, _ context: NSManagedObjectContext) -> Bool
|
private let reapplyAffectedStores: (_ fetchRequest: NSFetchRequest<NSManagedObject>, _ context: NSManagedObjectContext) throws -> Bool
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ public extension DataStack {
|
|||||||
|
|
||||||
```
|
```
|
||||||
dataStack.monitorList(
|
dataStack.monitorList(
|
||||||
{ (monitor) in
|
createAsynchronously: { (monitor) in
|
||||||
self.monitor = monitor
|
self.monitor = monitor
|
||||||
},
|
},
|
||||||
From<MyPersonEntity>()
|
From<MyPersonEntity>()
|
||||||
@@ -162,7 +162,6 @@ public extension DataStack {
|
|||||||
```
|
```
|
||||||
- parameter createAsynchronously: the closure that receives the created `ListMonitor` instance
|
- parameter createAsynchronously: the closure that receives the created `ListMonitor` instance
|
||||||
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
|
- 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<B: FetchChainableBuilderType>(createAsynchronously: @escaping (ListMonitor<B.ObjectType>) -> Void, _ clauseChain: B) {
|
public func monitorList<B: FetchChainableBuilderType>(createAsynchronously: @escaping (ListMonitor<B.ObjectType>) -> 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.
|
Asynchronously creates a `ListMonitor` for a sectioned list of `DynamicObject`s that satisfy the specified `SectionMonitorBuilderType` built from a chain of clauses.
|
||||||
```
|
```
|
||||||
dataStack.monitorSectionedList(
|
dataStack.monitorSectionedList(
|
||||||
{ (monitor) in
|
createAsynchronously: { (monitor) in
|
||||||
self.monitor = monitor
|
self.monitor = monitor
|
||||||
},
|
},
|
||||||
From<MyPersonEntity>()
|
From<MyPersonEntity>()
|
||||||
@@ -297,8 +296,8 @@ public extension DataStack {
|
|||||||
.orderBy(.ascending(\.age))
|
.orderBy(.ascending(\.age))
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
- parameter createAsynchronously: the closure that receives the created `ListMonitor` instance
|
||||||
- parameter clauseChain: a `SectionMonitorBuilderType` built from a chain of clauses
|
- 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<B: SectionMonitorBuilderType>(createAsynchronously: @escaping (ListMonitor<B.ObjectType>) -> Void, _ clauseChain: B) {
|
public func monitorSectionedList<B: SectionMonitorBuilderType>(createAsynchronously: @escaping (ListMonitor<B.ObjectType>) -> Void, _ clauseChain: B) {
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
- 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
|
||||||
*/
|
*/
|
||||||
public func fetchOne<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> D? {
|
public func fetchOne<D>(_ from: From<D>, _ fetchClauses: FetchClause...) throws -> D? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
"Attempted to fetch from a \(cs_typeName(self)) outside the main thread."
|
"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.
|
- 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
|
||||||
*/
|
*/
|
||||||
public func fetchOne<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> D? {
|
public func fetchOne<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) throws -> D? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
"Attempted to fetch from a \(cs_typeName(self)) outside the main thread."
|
"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
|
- 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`
|
||||||
*/
|
*/
|
||||||
public func fetchOne<B: FetchChainableBuilderType>(_ clauseChain: B) -> B.ObjectType? {
|
public func fetchOne<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> B.ObjectType? {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
"Attempted to fetch from a \(cs_typeName(self)) outside the main thread."
|
"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.
|
- 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
|
||||||
*/
|
*/
|
||||||
public func fetchAll<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> [D]? {
|
public func fetchAll<D>(_ from: From<D>, _ fetchClauses: FetchClause...) throws -> [D] {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
"Attempted to fetch from a \(cs_typeName(self)) outside the main thread."
|
"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.
|
- 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
|
||||||
*/
|
*/
|
||||||
public func fetchAll<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> [D]? {
|
public func fetchAll<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) throws -> [D] {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
"Attempted to fetch from a \(cs_typeName(self)) outside the main thread."
|
"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
|
- 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`
|
||||||
*/
|
*/
|
||||||
public func fetchAll<B: FetchChainableBuilderType>(_ clauseChain: B) -> [B.ObjectType]? {
|
public func fetchAll<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> [B.ObjectType] {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
"Attempted to fetch from a \(cs_typeName(self)) outside the main thread."
|
"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.
|
- 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 `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public func fetchCount<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> Int? {
|
public func fetchCount<D>(_ from: From<D>, _ fetchClauses: FetchClause...) throws -> Int {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
"Attempted to fetch from a \(cs_typeName(self)) outside the main thread."
|
"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.
|
- 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 `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
public func fetchCount<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> Int? {
|
public func fetchCount<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) throws -> Int {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
"Attempted to fetch from a \(cs_typeName(self)) outside the main thread."
|
"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
|
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
|
||||||
- returns: the number `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
|
- returns: the number `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
|
||||||
*/
|
*/
|
||||||
public func fetchCount<B: FetchChainableBuilderType>(_ clauseChain: B) -> Int? {
|
public func fetchCount<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> Int {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
Thread.isMainThread,
|
||||||
"Attempted to fetch from a \(cs_typeName(self)) outside the main thread."
|
"Attempted to fetch from a \(cs_typeName(self)) outside the main thread."
|
||||||
)
|
)
|
||||||
return self.mainContext.fetchCount(clauseChain)
|
return try self.mainContext.fetchCount(clauseChain)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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.
|
- 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
|
||||||
*/
|
*/
|
||||||
func fetchOne<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> D?
|
func fetchOne<D>(_ from: From<D>, _ fetchClauses: FetchClause...) throws -> D?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the first `DynamicObject` instance that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
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.
|
- 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
|
||||||
*/
|
*/
|
||||||
func fetchOne<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> D?
|
func fetchOne<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) throws -> D?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType` built from a chain of clauses.
|
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
|
- 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`
|
||||||
*/
|
*/
|
||||||
func fetchOne<B: FetchChainableBuilderType>(_ clauseChain: B) -> B.ObjectType?
|
func fetchOne<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> B.ObjectType?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
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.
|
- 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
|
||||||
*/
|
*/
|
||||||
func fetchAll<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> [D]?
|
func fetchAll<D>(_ from: From<D>, _ fetchClauses: FetchClause...) throws -> [D]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
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.
|
- 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
|
||||||
*/
|
*/
|
||||||
func fetchAll<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> [D]?
|
func fetchAll<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) throws -> [D]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses.
|
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
|
- 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`
|
||||||
*/
|
*/
|
||||||
func fetchAll<B: FetchChainableBuilderType>(_ clauseChain: B) -> [B.ObjectType]?
|
func fetchAll<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> [B.ObjectType]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
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.
|
- 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 `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
func fetchCount<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> Int?
|
func fetchCount<D>(_ from: From<D>, _ fetchClauses: FetchClause...) throws -> Int
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
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.
|
- 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 `DynamicObject`s that satisfy the specified `FetchClause`s
|
||||||
*/
|
*/
|
||||||
func fetchCount<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> Int?
|
func fetchCount<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) throws -> Int
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the number of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses.
|
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
|
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
|
||||||
- returns: the number `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
|
- returns: the number `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
|
||||||
*/
|
*/
|
||||||
func fetchCount<B: FetchChainableBuilderType>(_ clauseChain: B) -> Int?
|
func fetchCount<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> Int
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||||
|
|||||||
@@ -139,29 +139,40 @@ public struct From<D: DynamicObject> {
|
|||||||
self.findPersistentStores = findPersistentStores
|
self.findPersistentStores = findPersistentStores
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func applyToFetchRequest<ResultType>(_ fetchRequest: NSFetchRequest<ResultType>, context: NSManagedObjectContext, applyAffectedStores: Bool = true) -> Bool {
|
internal func applyToFetchRequest<U>(_ fetchRequest: NSFetchRequest<U>, context: NSManagedObjectContext, applyAffectedStores: Bool = true) throws {
|
||||||
|
|
||||||
fetchRequest.entity = context.parentStack!.entityDescription(for: EntityIdentifier(self.entityClass))!
|
fetchRequest.entity = context.parentStack!.entityDescription(for: EntityIdentifier(self.entityClass))!
|
||||||
guard applyAffectedStores else {
|
guard applyAffectedStores else {
|
||||||
|
|
||||||
return true
|
return
|
||||||
}
|
}
|
||||||
if self.applyAffectedStoresForFetchedRequest(fetchRequest, context: context) {
|
do {
|
||||||
|
|
||||||
return true
|
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<U>(_ fetchRequest: NSFetchRequest<U>, context: NSManagedObjectContext) -> Bool {
|
internal func applyAffectedStoresForFetchedRequest<U>(_ fetchRequest: NSFetchRequest<U>, context: NSManagedObjectContext) throws {
|
||||||
|
|
||||||
let stores = self.findPersistentStores(context)
|
let stores = self.findPersistentStores(context)
|
||||||
fetchRequest.affectedStores = stores
|
fetchRequest.affectedStores = stores
|
||||||
return stores?.isEmpty == false
|
if stores?.isEmpty == false {
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
throw CoreStoreError.persistentStoreNotFound(entity: self.entityClass)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ public final class ListMonitor<D: DynamicObject>: Hashable {
|
|||||||
*/
|
*/
|
||||||
public subscript(safeSectionIndex sectionIndex: Int, safeItemIndex itemIndex: Int) -> ObjectType? {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
@@ -202,9 +202,9 @@ public final class ListMonitor<D: DynamicObject>: Hashable {
|
|||||||
- parameter section: the section index. Using an index outside the valid range will return `false`.
|
- 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
|
- 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<D: DynamicObject>: Hashable {
|
|||||||
- parameter section: the section index. Using an index outside the valid range will raise an exception.
|
- 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
|
- 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<D: DynamicObject>: Hashable {
|
|||||||
- parameter section: the section index. Using an index outside the valid range will return `nil`.
|
- parameter section: the section index. Using an index outside the valid range will return `nil`.
|
||||||
- returns: the number of objects in the specified section
|
- 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<D: DynamicObject>: Hashable {
|
|||||||
- parameter section: the section index. Using an index outside the valid range will raise an exception.
|
- parameter section: the section index. Using an index outside the valid range will raise an exception.
|
||||||
- returns: the `NSFetchedResultsSectionInfo` for the specified section
|
- returns: the `NSFetchedResultsSectionInfo` for the specified section
|
||||||
*/
|
*/
|
||||||
public func sectionInfoAtIndex(_ section: Int) -> NSFetchedResultsSectionInfo {
|
public func sectionInfo(at section: Int) -> NSFetchedResultsSectionInfo {
|
||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
!self.isPendingRefetch || Thread.isMainThread,
|
!self.isPendingRefetch || Thread.isMainThread,
|
||||||
@@ -278,7 +278,7 @@ public final class ListMonitor<D: DynamicObject>: Hashable {
|
|||||||
- parameter section: the section index. Using an index outside the valid range will return `nil`.
|
- 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.
|
- 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(
|
CoreStore.assert(
|
||||||
!self.isPendingRefetch || Thread.isMainThread,
|
!self.isPendingRefetch || Thread.isMainThread,
|
||||||
@@ -312,17 +312,17 @@ public final class ListMonitor<D: DynamicObject>: Hashable {
|
|||||||
/**
|
/**
|
||||||
Returns the target section for a specified "Section Index" title and index.
|
Returns the target section for a specified "Section Index" title and index.
|
||||||
|
|
||||||
- parameter title: the title of the Section Index
|
- parameter sectionIndexTitle: the title of the Section Index
|
||||||
- parameter index: the index of the Section Index
|
- parameter sectionIndex: the index of the Section Index
|
||||||
- returns: the target section for the specified "Section Index" title and 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(
|
CoreStore.assert(
|
||||||
!self.isPendingRefetch || Thread.isMainThread,
|
!self.isPendingRefetch || Thread.isMainThread,
|
||||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
"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<D: DynamicObject>: Hashable {
|
|||||||
- parameter object: the `DynamicObject` to search the index of
|
- 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.
|
- 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(
|
CoreStore.assert(
|
||||||
!self.isPendingRefetch || Thread.isMainThread,
|
!self.isPendingRefetch || Thread.isMainThread,
|
||||||
@@ -364,7 +364,7 @@ public final class ListMonitor<D: DynamicObject>: Hashable {
|
|||||||
- parameter object: the `DynamicObject` to search the index of
|
- 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.
|
- 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(
|
CoreStore.assert(
|
||||||
!self.isPendingRefetch || Thread.isMainThread,
|
!self.isPendingRefetch || Thread.isMainThread,
|
||||||
@@ -1164,6 +1164,57 @@ public final class ListMonitor<D: DynamicObject>: Hashable {
|
|||||||
try! self.fetchedResultsController.performFetchFromSpecifiedStores()
|
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.
|
- parameter section: the section index. Using an index outside the valid range will raise an exception.
|
||||||
- returns: all objects in the specified section
|
- 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`.
|
- parameter section: the section index. Using an index outside the valid range will return `nil`.
|
||||||
- returns: all objects in the specified section
|
- returns: all objects in the specified section
|
||||||
*/
|
*/
|
||||||
|
public func objects(safelyIn section: Int) -> [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]? {
|
public func objectsInSection(safeSectionIndex section: Int) -> [ObjectType]? {
|
||||||
|
|
||||||
return self.sectionInfoAtIndex(safeSectionIndex: section)?.objects as! [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.
|
- parameter section: the section index. Using an index outside the valid range will raise an exception.
|
||||||
- returns: all objects in the specified section
|
- 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) })
|
.map({ ObjectType.cs_fromRaw(object: $0 as! NSManagedObject) })
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1248,10 +1314,25 @@ extension ListMonitor where ListMonitor.ObjectType: CoreStoreObject {
|
|||||||
- parameter section: the section index. Using an index outside the valid range will return `nil`.
|
- parameter section: the section index. Using an index outside the valid range will return `nil`.
|
||||||
- returns: all objects in the specified section
|
- returns: all objects in the specified section
|
||||||
*/
|
*/
|
||||||
|
public func objects(safelyIn section: Int) -> [ObjectType]? {
|
||||||
|
|
||||||
|
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]? {
|
public func objectsInSection(safeSectionIndex section: Int) -> [ObjectType]? {
|
||||||
|
|
||||||
return (self.sectionInfoAtIndex(safeSectionIndex: section)?.objects)?
|
return self.objects(safelyIn: section)
|
||||||
.map({ ObjectType.cs_fromRaw(object: $0 as! NSManagedObject) })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,85 +34,65 @@ internal extension NSManagedObjectContext {
|
|||||||
// MARK: Internal
|
// MARK: Internal
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func fetchOne(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) -> NSManagedObject? {
|
internal func fetchOne(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) throws -> NSManagedObject? {
|
||||||
|
|
||||||
let fetchRequest = CoreStoreFetchRequest()
|
let fetchRequest = CoreStoreFetchRequest()
|
||||||
let storeFound = from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self)
|
try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self)
|
||||||
|
|
||||||
fetchRequest.fetchLimit = 1
|
fetchRequest.fetchLimit = 1
|
||||||
fetchRequest.resultType = .managedObjectResultType
|
fetchRequest.resultType = .managedObjectResultType
|
||||||
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
|
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
|
||||||
|
|
||||||
guard storeFound else {
|
return try self.fetchOne(fetchRequest.dynamicCast())
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return self.fetchOne(fetchRequest.dynamicCast())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func fetchAll<T: NSManagedObject>(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) -> [T]? {
|
internal func fetchAll<T: NSManagedObject>(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) throws -> [T] {
|
||||||
|
|
||||||
let fetchRequest = CoreStoreFetchRequest()
|
let fetchRequest = CoreStoreFetchRequest()
|
||||||
let storeFound = from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self)
|
try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self)
|
||||||
|
|
||||||
fetchRequest.fetchLimit = 0
|
fetchRequest.fetchLimit = 0
|
||||||
fetchRequest.resultType = .managedObjectResultType
|
fetchRequest.resultType = .managedObjectResultType
|
||||||
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
|
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
|
||||||
|
|
||||||
guard storeFound else {
|
return try self.fetchAll(fetchRequest.dynamicCast())
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return self.fetchAll(fetchRequest.dynamicCast())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func fetchCount(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) -> Int? {
|
internal func fetchCount(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) throws -> Int {
|
||||||
|
|
||||||
let fetchRequest = CoreStoreFetchRequest()
|
let fetchRequest = CoreStoreFetchRequest()
|
||||||
let storeFound = from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self)
|
try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self)
|
||||||
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
|
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
|
||||||
|
|
||||||
guard storeFound else {
|
return try self.fetchCount(fetchRequest.dynamicCast())
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return self.fetchCount(fetchRequest.dynamicCast())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func fetchObjectID(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) -> NSManagedObjectID? {
|
internal func fetchObjectID(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) throws -> NSManagedObjectID? {
|
||||||
|
|
||||||
let fetchRequest = CoreStoreFetchRequest()
|
let fetchRequest = CoreStoreFetchRequest()
|
||||||
let storeFound = from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self)
|
try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self)
|
||||||
|
|
||||||
fetchRequest.fetchLimit = 1
|
fetchRequest.fetchLimit = 1
|
||||||
fetchRequest.resultType = .managedObjectIDResultType
|
fetchRequest.resultType = .managedObjectIDResultType
|
||||||
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
|
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
|
||||||
|
|
||||||
guard storeFound else {
|
return try self.fetchObjectID(fetchRequest.dynamicCast())
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return self.fetchObjectID(fetchRequest.dynamicCast())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func fetchObjectIDs(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) -> [NSManagedObjectID]? {
|
internal func fetchObjectIDs(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) throws -> [NSManagedObjectID] {
|
||||||
|
|
||||||
let fetchRequest = CoreStoreFetchRequest()
|
let fetchRequest = CoreStoreFetchRequest()
|
||||||
let storeFound = from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self)
|
try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self)
|
||||||
|
|
||||||
fetchRequest.fetchLimit = 0
|
fetchRequest.fetchLimit = 0
|
||||||
fetchRequest.resultType = .managedObjectIDResultType
|
fetchRequest.resultType = .managedObjectIDResultType
|
||||||
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
|
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
|
||||||
|
|
||||||
guard storeFound else {
|
return try self.fetchObjectIDs(fetchRequest.dynamicCast())
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return self.fetchObjectIDs(fetchRequest.dynamicCast())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
|
|||||||
@@ -101,88 +101,76 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchOne<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> D? {
|
public func fetchOne<D>(_ from: From<D>, _ fetchClauses: FetchClause...) throws -> D? {
|
||||||
|
|
||||||
return self.fetchOne(from, fetchClauses)
|
return try self.fetchOne(from, fetchClauses)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchOne<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> D? {
|
public func fetchOne<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) throws -> D? {
|
||||||
|
|
||||||
let fetchRequest = CoreStoreFetchRequest()
|
let fetchRequest = CoreStoreFetchRequest()
|
||||||
let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
try from.applyToFetchRequest(fetchRequest, context: self)
|
||||||
|
|
||||||
fetchRequest.fetchLimit = 1
|
fetchRequest.fetchLimit = 1
|
||||||
fetchRequest.resultType = .managedObjectResultType
|
fetchRequest.resultType = .managedObjectResultType
|
||||||
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
|
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
|
||||||
|
|
||||||
guard storeFound else {
|
return try self.fetchOne(fetchRequest.dynamicCast()).flatMap(from.entityClass.cs_fromRaw)
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return self.fetchOne(fetchRequest.dynamicCast()).flatMap(from.entityClass.cs_fromRaw)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchOne<B: FetchChainableBuilderType>(_ clauseChain: B) -> B.ObjectType? {
|
public func fetchOne<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> B.ObjectType? {
|
||||||
|
|
||||||
return self.fetchOne(clauseChain.from, clauseChain.fetchClauses)
|
return try self.fetchOne(clauseChain.from, clauseChain.fetchClauses)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchAll<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> [D]? {
|
public func fetchAll<D>(_ from: From<D>, _ fetchClauses: FetchClause...) throws -> [D] {
|
||||||
|
|
||||||
return self.fetchAll(from, fetchClauses)
|
return try self.fetchAll(from, fetchClauses)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchAll<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> [D]? {
|
public func fetchAll<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) throws -> [D] {
|
||||||
|
|
||||||
let fetchRequest = CoreStoreFetchRequest()
|
let fetchRequest = CoreStoreFetchRequest()
|
||||||
let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
try from.applyToFetchRequest(fetchRequest, context: self)
|
||||||
|
|
||||||
fetchRequest.fetchLimit = 0
|
fetchRequest.fetchLimit = 0
|
||||||
fetchRequest.resultType = .managedObjectResultType
|
fetchRequest.resultType = .managedObjectResultType
|
||||||
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
|
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
|
||||||
|
|
||||||
guard storeFound else {
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
let entityClass = from.entityClass
|
let entityClass = from.entityClass
|
||||||
return self.fetchAll(fetchRequest.dynamicCast())?.map(entityClass.cs_fromRaw)
|
return try self.fetchAll(fetchRequest.dynamicCast())?.map(entityClass.cs_fromRaw)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchAll<B: FetchChainableBuilderType>(_ clauseChain: B) -> [B.ObjectType]? {
|
public func fetchAll<B: FetchChainableBuilderType>(_ clauseChain: B) throw -> [B.ObjectType] {
|
||||||
|
|
||||||
return self.fetchAll(clauseChain.from, clauseChain.fetchClauses)
|
return try self.fetchAll(clauseChain.from, clauseChain.fetchClauses)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchCount<D>(_ from: From<D>, _ fetchClauses: FetchClause...) -> Int? {
|
public func fetchCount<D>(_ from: From<D>, _ fetchClauses: FetchClause...) throws -> Int {
|
||||||
|
|
||||||
return self.fetchCount(from, fetchClauses)
|
return try self.fetchCount(from, fetchClauses)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchCount<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> Int? {
|
public func fetchCount<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) throws -> Int {
|
||||||
|
|
||||||
let fetchRequest = CoreStoreFetchRequest()
|
let fetchRequest = CoreStoreFetchRequest()
|
||||||
let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
try from.applyToFetchRequest(fetchRequest, context: self)
|
||||||
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
|
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
|
||||||
|
|
||||||
guard storeFound else {
|
return try self.fetchCount(fetchRequest.dynamicCast())
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return self.fetchCount(fetchRequest.dynamicCast())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchCount<B: FetchChainableBuilderType>(_ clauseChain: B) -> Int? {
|
public func fetchCount<B: FetchChainableBuilderType>(_ clauseChain: B) throws -> Int {
|
||||||
|
|
||||||
return self.fetchCount(clauseChain.from, clauseChain.fetchClauses)
|
return try self.fetchCount(clauseChain.from, clauseChain.fetchClauses)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
@@ -208,7 +196,6 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
|||||||
return self.fetchObjectID(fetchRequest.dynamicCast())
|
return self.fetchObjectID(fetchRequest.dynamicCast())
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: docs
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchObjectID<B: FetchChainableBuilderType>(_ clauseChain: B) -> NSManagedObjectID? {
|
public func fetchObjectID<B: FetchChainableBuilderType>(_ clauseChain: B) -> NSManagedObjectID? {
|
||||||
|
|
||||||
@@ -225,7 +212,7 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
|||||||
public func fetchObjectIDs<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? {
|
public func fetchObjectIDs<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? {
|
||||||
|
|
||||||
let fetchRequest = CoreStoreFetchRequest()
|
let fetchRequest = CoreStoreFetchRequest()
|
||||||
let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
try from.applyToFetchRequest(fetchRequest, context: self)
|
||||||
|
|
||||||
fetchRequest.fetchLimit = 0
|
fetchRequest.fetchLimit = 0
|
||||||
fetchRequest.resultType = .managedObjectIDResultType
|
fetchRequest.resultType = .managedObjectIDResultType
|
||||||
@@ -238,7 +225,6 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
|||||||
return self.fetchObjectIDs(fetchRequest.dynamicCast())
|
return self.fetchObjectIDs(fetchRequest.dynamicCast())
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: docs
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
public func fetchObjectIDs<B: FetchChainableBuilderType>(_ clauseChain: B) -> [NSManagedObjectID]? {
|
public func fetchObjectIDs<B: FetchChainableBuilderType>(_ clauseChain: B) -> [NSManagedObjectID]? {
|
||||||
|
|
||||||
@@ -383,7 +369,7 @@ internal extension NSManagedObjectContext {
|
|||||||
// MARK: Fetching
|
// MARK: Fetching
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func fetchOne<D: NSManagedObject>(_ fetchRequest: NSFetchRequest<D>) -> D? {
|
internal func fetchOne<D: NSManagedObject>(_ fetchRequest: NSFetchRequest<D>) throws -> D? {
|
||||||
|
|
||||||
var fetchResults: [D]?
|
var fetchResults: [D]?
|
||||||
var fetchError: Error?
|
var fetchError: Error?
|
||||||
@@ -400,17 +386,18 @@ internal extension NSManagedObjectContext {
|
|||||||
}
|
}
|
||||||
if fetchResults == nil {
|
if fetchResults == nil {
|
||||||
|
|
||||||
|
let coreStoreError = CoreStoreError(fetchError)
|
||||||
CoreStore.log(
|
CoreStore.log(
|
||||||
CoreStoreError(fetchError),
|
coreStoreError,
|
||||||
"Failed executing fetch request."
|
"Failed executing fetch request."
|
||||||
)
|
)
|
||||||
return nil
|
throw coreStoreError
|
||||||
}
|
}
|
||||||
return fetchResults?.first
|
return fetchResults?.first
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func fetchAll<D: NSManagedObject>(_ fetchRequest: NSFetchRequest<D>) -> [D]? {
|
internal func fetchAll<D: NSManagedObject>(_ fetchRequest: NSFetchRequest<D>) throws -> [D] {
|
||||||
|
|
||||||
var fetchResults: [D]?
|
var fetchResults: [D]?
|
||||||
var fetchError: Error?
|
var fetchError: Error?
|
||||||
@@ -427,17 +414,18 @@ internal extension NSManagedObjectContext {
|
|||||||
}
|
}
|
||||||
if fetchResults == nil {
|
if fetchResults == nil {
|
||||||
|
|
||||||
|
let coreStoreError = CoreStoreError(fetchError)
|
||||||
CoreStore.log(
|
CoreStore.log(
|
||||||
CoreStoreError(fetchError),
|
coreStoreError,
|
||||||
"Failed executing fetch request."
|
"Failed executing fetch request."
|
||||||
)
|
)
|
||||||
return nil
|
throw coreStoreError
|
||||||
}
|
}
|
||||||
return fetchResults
|
return fetchResults
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func fetchCount(_ fetchRequest: NSFetchRequest<NSFetchRequestResult>) -> Int? {
|
internal func fetchCount(_ fetchRequest: NSFetchRequest<NSFetchRequestResult>) throws -> Int {
|
||||||
|
|
||||||
var count = 0
|
var count = 0
|
||||||
var countError: Error?
|
var countError: Error?
|
||||||
@@ -454,11 +442,12 @@ internal extension NSManagedObjectContext {
|
|||||||
}
|
}
|
||||||
if count == NSNotFound {
|
if count == NSNotFound {
|
||||||
|
|
||||||
|
let coreStoreError = CoreStoreError(fetchError)
|
||||||
CoreStore.log(
|
CoreStore.log(
|
||||||
CoreStoreError(countError),
|
coreStoreError,
|
||||||
"Failed executing count request."
|
"Failed executing count request."
|
||||||
)
|
)
|
||||||
return nil
|
throw coreStoreError
|
||||||
}
|
}
|
||||||
return count
|
return count
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -143,7 +143,22 @@ public extension UnsafeDataTransaction {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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<MyPersonEntity>()
|
||||||
|
.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<B: FetchChainableBuilderType>(createAsynchronously: @escaping (ListMonitor<B.ObjectType>) -> Void, _ clauseChain: B) {
|
public func monitorList<B: FetchChainableBuilderType>(createAsynchronously: @escaping (ListMonitor<B.ObjectType>) -> Void, _ clauseChain: B) {
|
||||||
|
|
||||||
self.monitorList(
|
self.monitorList(
|
||||||
@@ -267,8 +282,8 @@ public extension UnsafeDataTransaction {
|
|||||||
.orderBy(.ascending(\.age))
|
.orderBy(.ascending(\.age))
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
- parameter createAsynchronously: the closure that receives the created `ListMonitor` instance
|
||||||
- parameter clauseChain: a `SectionMonitorBuilderType` built from a chain of clauses
|
- 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<B: SectionMonitorBuilderType>(createAsynchronously: @escaping (ListMonitor<B.ObjectType>) -> Void, _ clauseChain: B) {
|
public func monitorSectionedList<B: SectionMonitorBuilderType>(createAsynchronously: @escaping (ListMonitor<B.ObjectType>) -> Void, _ clauseChain: B) {
|
||||||
|
|
||||||
|
|||||||
@@ -541,7 +541,7 @@ public extension Sequence where Iterator.Element: WhereClauseType {
|
|||||||
|
|
||||||
public extension Where {
|
public extension Where {
|
||||||
|
|
||||||
@available(*, deprecated: 4.0, renamed: "&&?")
|
@available(*, deprecated, renamed: "&&?")
|
||||||
public static func && (left: Where<D>, right: Where<D>?) -> Where<D> {
|
public static func && (left: Where<D>, right: Where<D>?) -> Where<D> {
|
||||||
|
|
||||||
if let right = right {
|
if let right = right {
|
||||||
@@ -551,7 +551,7 @@ public extension Where {
|
|||||||
return left
|
return left
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(*, deprecated: 4.0, renamed: "&&?")
|
@available(*, deprecated, renamed: "&&?")
|
||||||
public static func && (left: Where<D>?, right: Where<D>) -> Where<D> {
|
public static func && (left: Where<D>?, right: Where<D>) -> Where<D> {
|
||||||
|
|
||||||
if let left = left {
|
if let left = left {
|
||||||
@@ -561,7 +561,7 @@ public extension Where {
|
|||||||
return right
|
return right
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(*, deprecated: 4.0, renamed: "||?")
|
@available(*, deprecated, renamed: "||?")
|
||||||
public static func || (left: Where<D>, right: Where<D>?) -> Where<D> {
|
public static func || (left: Where<D>, right: Where<D>?) -> Where<D> {
|
||||||
|
|
||||||
if let right = right {
|
if let right = right {
|
||||||
@@ -571,7 +571,7 @@ public extension Where {
|
|||||||
return left
|
return left
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(*, deprecated: 4.0, renamed: "||?")
|
@available(*, deprecated, renamed: "||?")
|
||||||
public static func || (left: Where<D>?, right: Where<D>) -> Where<D> {
|
public static func || (left: Where<D>?, right: Where<D>) -> Where<D> {
|
||||||
|
|
||||||
if let left = left {
|
if let left = left {
|
||||||
|
|||||||
Reference in New Issue
Block a user