mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-04-24 09:38:30 +02:00
WIP
This commit is contained in:
@@ -37,7 +37,6 @@ public extension BaseDataTransaction {
|
||||
- parameter object: a reference to the object created/fetched outside the transaction
|
||||
- returns: the `NSManagedObject` instance if the object exists in the transaction, or `nil` if not found.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchExisting<T: NSManagedObject>(_ object: T) -> T? {
|
||||
|
||||
do {
|
||||
@@ -56,7 +55,6 @@ public extension BaseDataTransaction {
|
||||
- parameter objectID: the `NSManagedObjectID` for the object
|
||||
- returns: the `NSManagedObject` instance if the object exists in the transaction, or `nil` if not found.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchExisting<T: NSManagedObject>(_ objectID: NSManagedObjectID) -> T? {
|
||||
|
||||
do {
|
||||
@@ -75,7 +73,6 @@ public extension BaseDataTransaction {
|
||||
- parameter objects: an array of `NSManagedObject`s created/fetched outside the transaction
|
||||
- returns: the `NSManagedObject` array for objects that exists in the transaction
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchExisting<T: NSManagedObject, S: Sequence where S.Iterator.Element == T>(_ objects: S) -> [T] {
|
||||
|
||||
return objects.flatMap { (try? self.context.existingObject(with: $0.objectID)) as? T }
|
||||
@@ -87,7 +84,6 @@ public extension BaseDataTransaction {
|
||||
- parameter objectIDs: the `NSManagedObjectID` array for the objects
|
||||
- returns: the `NSManagedObject` array for objects that exists in the transaction
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchExisting<T: NSManagedObject, S: Sequence where S.Iterator.Element == NSManagedObjectID>(_ objectIDs: S) -> [T] {
|
||||
|
||||
return objectIDs.flatMap { (try? self.context.existingObject(with: $0)) as? T }
|
||||
@@ -100,7 +96,6 @@ public extension BaseDataTransaction {
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: the first `NSManagedObject` instance that satisfies the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchOne<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> T? {
|
||||
|
||||
return self.fetchOne(from, fetchClauses)
|
||||
@@ -113,7 +108,6 @@ public extension BaseDataTransaction {
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: the first `NSManagedObject` instance that satisfies the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchOne<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> T? {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -130,7 +124,6 @@ public extension BaseDataTransaction {
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: all `NSManagedObject` instances that satisfy the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchAll<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [T]? {
|
||||
|
||||
return self.fetchAll(from, fetchClauses)
|
||||
@@ -143,7 +136,6 @@ public extension BaseDataTransaction {
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: all `NSManagedObject` instances that satisfy the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchAll<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [T]? {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -160,7 +152,6 @@ public extension BaseDataTransaction {
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: the number `NSManagedObject`s that satisfy the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchCount<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> Int? {
|
||||
|
||||
return self.fetchCount(from, fetchClauses)
|
||||
@@ -173,7 +164,6 @@ public extension BaseDataTransaction {
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: the number `NSManagedObject`s that satisfy the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchCount<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> Int? {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -191,7 +181,6 @@ public extension BaseDataTransaction {
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: the `NSManagedObjectID` for the first `NSManagedObject` that satisfies the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchObjectID<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> NSManagedObjectID? {
|
||||
|
||||
return self.fetchObjectID(from, fetchClauses)
|
||||
@@ -204,7 +193,6 @@ public extension BaseDataTransaction {
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: the `NSManagedObjectID` for the first `NSManagedObject` that satisfies the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchObjectID<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -221,7 +209,6 @@ public extension BaseDataTransaction {
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: the `NSManagedObjectID` for all `NSManagedObject`s that satisfy the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchObjectIDs<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? {
|
||||
|
||||
return self.fetchObjectIDs(from, fetchClauses)
|
||||
@@ -234,7 +221,6 @@ public extension BaseDataTransaction {
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: the `NSManagedObjectID` for all `NSManagedObject`s that satisfy the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchObjectIDs<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -251,6 +237,7 @@ public extension BaseDataTransaction {
|
||||
- parameter deleteClauses: a series of `DeleteClause` instances for the delete request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: the number of `NSManagedObject`s deleted
|
||||
*/
|
||||
@discardableResult
|
||||
public func deleteAll<T: NSManagedObject>(_ from: From<T>, _ deleteClauses: DeleteClause...) -> Int? {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -268,6 +255,7 @@ public extension BaseDataTransaction {
|
||||
- parameter deleteClauses: a series of `DeleteClause` instances for the delete request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: the number of `NSManagedObject`s deleted
|
||||
*/
|
||||
@discardableResult
|
||||
public func deleteAll<T: NSManagedObject>(_ from: From<T>, _ deleteClauses: [DeleteClause]) -> Int? {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -288,7 +276,6 @@ public extension BaseDataTransaction {
|
||||
- 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<U>` parameter.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -309,7 +296,6 @@ public extension BaseDataTransaction {
|
||||
- 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<U>` parameter.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -330,7 +316,6 @@ public extension BaseDataTransaction {
|
||||
- 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<U>` parameter.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[NSString: AnyObject]]? {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -351,7 +336,6 @@ public extension BaseDataTransaction {
|
||||
- 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<U>` parameter.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[NSString: AnyObject]]? {
|
||||
|
||||
CoreStore.assert(
|
||||
|
||||
@@ -32,7 +32,7 @@ import CoreData
|
||||
/**
|
||||
A `From` clause specifies the source entity and source persistent store for fetch and query methods. A common usage is to just indicate the entity:
|
||||
```
|
||||
let person = transaction.fetchOne(From(MyPersonEntity))
|
||||
let person = transaction.fetchOne(From<MyPersonEntity>())
|
||||
```
|
||||
For cases where multiple `NSPersistentStore`s contain the same entity, the source configuration's name needs to be specified as well:
|
||||
```
|
||||
@@ -88,7 +88,7 @@ public struct From<T: NSManagedObject> {
|
||||
|
||||
CoreStore.assert(
|
||||
entityClass is T.Type,
|
||||
"Attempted to create generic type \(cs_typeName(From<T>)) with entity class \(cs_typeName(entityClass))"
|
||||
"Attempted to create generic type \(cs_typeName(From<T>.self)) with entity class \(cs_typeName(entityClass))"
|
||||
)
|
||||
self.init(entityClass: entityClass, configurations: nil)
|
||||
}
|
||||
@@ -163,7 +163,7 @@ public struct From<T: NSManagedObject> {
|
||||
|
||||
CoreStore.assert(
|
||||
entityClass is T.Type,
|
||||
"Attempted to create generic type \(cs_typeName(From<T>)) with entity class \(cs_typeName(entityClass))"
|
||||
"Attempted to create generic type \(cs_typeName(From<T>.self)) with entity class \(cs_typeName(entityClass))"
|
||||
)
|
||||
self.init(entityClass: entityClass, configurations: [configuration] + otherConfigurations)
|
||||
}
|
||||
@@ -181,7 +181,7 @@ public struct From<T: NSManagedObject> {
|
||||
|
||||
CoreStore.assert(
|
||||
entityClass is T.Type,
|
||||
"Attempted to create generic type \(cs_typeName(From<T>)) with entity class \(cs_typeName(entityClass))"
|
||||
"Attempted to create generic type \(cs_typeName(From<T>.self)) with entity class \(cs_typeName(entityClass))"
|
||||
)
|
||||
self.init(entityClass: entityClass, configurations: configurations)
|
||||
}
|
||||
@@ -189,7 +189,6 @@ public struct From<T: NSManagedObject> {
|
||||
|
||||
// MARK: Internal
|
||||
|
||||
@warn_unused_result
|
||||
internal func applyToFetchRequest<ResultType: NSFetchRequestResult>(_ fetchRequest: NSFetchRequest<ResultType>, context: NSManagedObjectContext, applyAffectedStores: Bool = true) -> Bool {
|
||||
|
||||
fetchRequest.entity = context.entityDescriptionForEntityClass(self.entityClass)
|
||||
|
||||
@@ -96,7 +96,6 @@ public struct GroupBy: QueryClause, Hashable {
|
||||
|
||||
// MARK: - GroupBy: Equatable
|
||||
|
||||
@warn_unused_result
|
||||
public func == (lhs: GroupBy, rhs: GroupBy) -> Bool {
|
||||
|
||||
return lhs.keyPaths == rhs.keyPaths
|
||||
|
||||
@@ -27,12 +27,12 @@ import Foundation
|
||||
import CoreData
|
||||
|
||||
|
||||
public func +(left: OrderBy, right: OrderBy) -> OrderBy {
|
||||
public func + (left: OrderBy, right: OrderBy) -> OrderBy {
|
||||
|
||||
return OrderBy(left.sortDescriptors + right.sortDescriptors)
|
||||
}
|
||||
|
||||
public func +=(left: inout OrderBy, right: OrderBy) {
|
||||
public func += (left: inout OrderBy, right: OrderBy) {
|
||||
|
||||
left = left + right
|
||||
}
|
||||
@@ -163,7 +163,6 @@ public struct OrderBy: FetchClause, QueryClause, DeleteClause, Hashable {
|
||||
|
||||
// MARK: - OrderBy: Equatable
|
||||
|
||||
@warn_unused_result
|
||||
public func == (lhs: OrderBy, rhs: OrderBy) -> Bool {
|
||||
|
||||
return lhs.sortDescriptors == rhs.sortDescriptors
|
||||
|
||||
@@ -70,15 +70,15 @@ public enum SelectTerm: StringLiteralConvertible, Hashable {
|
||||
Provides a `SelectTerm` to a `Select` clause for querying an entity attribute. A shorter way to do the same is to assign from the string keypath directly:
|
||||
```
|
||||
let fullName = CoreStore.queryValue(
|
||||
From(MyPersonEntity),
|
||||
Select<String>(.Attribute("fullName")),
|
||||
From<MyPersonEntity>(),
|
||||
Select<String>(.attribute("fullName")),
|
||||
Where("employeeID", isEqualTo: 1111)
|
||||
)
|
||||
```
|
||||
is equivalent to:
|
||||
```
|
||||
let fullName = CoreStore.queryValue(
|
||||
From(MyPersonEntity),
|
||||
From<MyPersonEntity>(),
|
||||
Select<String>("fullName"),
|
||||
Where("employeeID", isEqualTo: 1111)
|
||||
)
|
||||
@@ -96,8 +96,8 @@ public enum SelectTerm: StringLiteralConvertible, Hashable {
|
||||
Provides a `SelectTerm` to a `Select` clause for querying the average value of an attribute.
|
||||
```
|
||||
let averageAge = CoreStore.queryValue(
|
||||
From(MyPersonEntity),
|
||||
Select<Int>(.Average("age"))
|
||||
From<MyPersonEntity>(),
|
||||
Select<Int>(.average("age"))
|
||||
)
|
||||
```
|
||||
|
||||
@@ -119,8 +119,8 @@ public enum SelectTerm: StringLiteralConvertible, Hashable {
|
||||
Provides a `SelectTerm` to a `Select` clause for a count query.
|
||||
```
|
||||
let numberOfEmployees = CoreStore.queryValue(
|
||||
From(MyPersonEntity),
|
||||
Select<Int>(.Count("employeeID"))
|
||||
From<MyPersonEntity>(),
|
||||
Select<Int>(.count("employeeID"))
|
||||
)
|
||||
```
|
||||
|
||||
@@ -142,8 +142,8 @@ public enum SelectTerm: StringLiteralConvertible, Hashable {
|
||||
Provides a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute.
|
||||
```
|
||||
let maximumAge = CoreStore.queryValue(
|
||||
From(MyPersonEntity),
|
||||
Select<Int>(.Maximum("age"))
|
||||
From<MyPersonEntity>(),
|
||||
Select<Int>(.maximum("age"))
|
||||
)
|
||||
```
|
||||
|
||||
@@ -165,8 +165,8 @@ public enum SelectTerm: StringLiteralConvertible, Hashable {
|
||||
Provides a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute.
|
||||
```
|
||||
let minimumAge = CoreStore.queryValue(
|
||||
From(MyPersonEntity),
|
||||
Select<Int>(.Minimum("age"))
|
||||
From<MyPersonEntity>(),
|
||||
Select<Int>(.minimum("age"))
|
||||
)
|
||||
```
|
||||
|
||||
@@ -188,8 +188,8 @@ public enum SelectTerm: StringLiteralConvertible, Hashable {
|
||||
Provides a `SelectTerm` to a `Select` clause for querying the sum value for an attribute.
|
||||
```
|
||||
let totalAge = CoreStore.queryValue(
|
||||
From(MyPersonEntity),
|
||||
Select<Int>(.Sum("age"))
|
||||
From<MyPersonEntity>(),
|
||||
Select<Int>(.sum("age"))
|
||||
)
|
||||
```
|
||||
|
||||
@@ -211,7 +211,7 @@ public enum SelectTerm: StringLiteralConvertible, Hashable {
|
||||
Provides a `SelectTerm` to a `Select` clause for querying the `NSManagedObjectID`.
|
||||
```
|
||||
let objectID = CoreStore.queryValue(
|
||||
From(MyPersonEntity),
|
||||
From<MyPersonEntity>(),
|
||||
Select<NSManagedObjectID>(),
|
||||
Where("employeeID", isEqualTo: 1111)
|
||||
)
|
||||
@@ -276,7 +276,6 @@ public enum SelectTerm: StringLiteralConvertible, Hashable {
|
||||
|
||||
// MARK: - SelectTerm: Equatable
|
||||
|
||||
@warn_unused_result
|
||||
public func == (lhs: SelectTerm, rhs: SelectTerm) -> Bool {
|
||||
|
||||
switch (lhs, rhs) {
|
||||
@@ -308,15 +307,15 @@ public func == (lhs: SelectTerm, rhs: SelectTerm) -> Bool {
|
||||
You can bind the return type by specializing the initializer:
|
||||
```
|
||||
let maximumAge = CoreStore.queryValue(
|
||||
From(MyPersonEntity),
|
||||
Select<Int>(.Maximum("age"))
|
||||
From<MyPersonEntity>(),
|
||||
Select<Int>(.maximum("age"))
|
||||
)
|
||||
```
|
||||
or by casting the type of the return value:
|
||||
```
|
||||
let maximumAge: Int = CoreStore.queryValue(
|
||||
From(MyPersonEntity),
|
||||
Select(.Maximum("age"))
|
||||
From<MyPersonEntity>(),
|
||||
Select(.maximum("age"))
|
||||
)
|
||||
```
|
||||
Valid return types depend on the query:
|
||||
@@ -395,7 +394,6 @@ public extension Select where T: NSManagedObjectID {
|
||||
|
||||
// MARK: - Select: Equatable
|
||||
|
||||
@warn_unused_result
|
||||
public func == <T: SelectResultType, U: SelectResultType>(lhs: Select<T>, rhs: Select<U>) -> Bool {
|
||||
|
||||
return lhs.selectTerms == rhs.selectTerms
|
||||
@@ -573,6 +571,38 @@ extension String: SelectValueResultType {
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Date: SelectValueResultType
|
||||
|
||||
extension Date: SelectValueResultType {
|
||||
|
||||
public static var attributeType: NSAttributeType {
|
||||
|
||||
return .dateAttributeType
|
||||
}
|
||||
|
||||
public static func fromResultObject(_ result: AnyObject) -> Date? {
|
||||
|
||||
return result as? Date
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Data: SelectValueResultType
|
||||
|
||||
extension Data: SelectValueResultType {
|
||||
|
||||
public static var attributeType: NSAttributeType {
|
||||
|
||||
return .binaryDataAttributeType
|
||||
}
|
||||
|
||||
public static func fromResultObject(_ result: AnyObject) -> Data? {
|
||||
|
||||
return result as? Data
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - NSNumber: SelectValueResultType
|
||||
|
||||
extension NSNumber: SelectValueResultType {
|
||||
@@ -635,32 +665,40 @@ extension NSDecimalNumber {
|
||||
|
||||
// MARK: - NSDate: SelectValueResultType
|
||||
|
||||
extension Date: SelectValueResultType {
|
||||
extension NSDate: SelectValueResultType {
|
||||
|
||||
public static var attributeType: NSAttributeType {
|
||||
|
||||
return .dateAttributeType
|
||||
}
|
||||
|
||||
public static func fromResultObject(_ result: AnyObject) -> Date? {
|
||||
public class func fromResultObject(_ result: AnyObject) -> Self? {
|
||||
|
||||
return result as? Date
|
||||
func forceCast<T: NSDate>(_ object: AnyObject) -> T? {
|
||||
|
||||
return (object as? T)
|
||||
}
|
||||
return forceCast(result)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - NSData: SelectValueResultType
|
||||
|
||||
extension Data: SelectValueResultType {
|
||||
extension NSData: SelectValueResultType {
|
||||
|
||||
public static var attributeType: NSAttributeType {
|
||||
|
||||
return .binaryDataAttributeType
|
||||
}
|
||||
|
||||
public static func fromResultObject(_ result: AnyObject) -> Data? {
|
||||
public class func fromResultObject(_ result: AnyObject) -> Self? {
|
||||
|
||||
return result as? Data
|
||||
func forceCast<T: NSData>(_ object: AnyObject) -> T? {
|
||||
|
||||
return (object as? T)
|
||||
}
|
||||
return forceCast(result)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ import CoreData
|
||||
Sample usage:
|
||||
```
|
||||
let employees = transaction.fetchAll(
|
||||
From(MyPersonEntity),
|
||||
From<MyPersonEntity>(),
|
||||
Tweak { (fetchRequest) -> Void in
|
||||
fetchRequest.includesPendingChanges = false
|
||||
fetchRequest.fetchLimit = 5
|
||||
|
||||
@@ -27,17 +27,17 @@ import Foundation
|
||||
import CoreData
|
||||
|
||||
|
||||
public func &&(left: Where, right: Where) -> Where {
|
||||
public func && (left: Where, right: Where) -> Where {
|
||||
|
||||
return Where(CompoundPredicate(type: .and, subpredicates: [left.predicate, right.predicate]))
|
||||
}
|
||||
|
||||
public func ||(left: Where, right: Where) -> Where {
|
||||
public func || (left: Where, right: Where) -> Where {
|
||||
|
||||
return Where(CompoundPredicate(type: .or, subpredicates: [left.predicate, right.predicate]))
|
||||
}
|
||||
|
||||
public prefix func !(clause: Where) -> Where {
|
||||
public prefix func ! (clause: Where) -> Where {
|
||||
|
||||
return Where(CompoundPredicate(type: .not, subpredicates: [clause.predicate]))
|
||||
}
|
||||
@@ -168,7 +168,6 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
|
||||
|
||||
// MARK: - Where: Equatable
|
||||
|
||||
@warn_unused_result
|
||||
public func == (lhs: Where, rhs: Where) -> Bool {
|
||||
|
||||
return lhs.predicate == rhs.predicate
|
||||
|
||||
@@ -37,7 +37,6 @@ public extension CoreStore {
|
||||
- parameter object: a reference to the object created/fetched outside the `DataStack`
|
||||
- returns: the `NSManagedObject` instance if the object exists in the `DataStack`, or `nil` if not found.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public static func fetchExisting<T: NSManagedObject>(_ object: T) -> T? {
|
||||
|
||||
return self.defaultStack.fetchExisting(object)
|
||||
@@ -49,7 +48,6 @@ public extension CoreStore {
|
||||
- parameter objectID: the `NSManagedObjectID` for the object
|
||||
- returns: the `NSManagedObject` instance if the object exists in the `DataStack`, or `nil` if not found.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public static func fetchExisting<T: NSManagedObject>(_ objectID: NSManagedObjectID) -> T? {
|
||||
|
||||
return self.defaultStack.fetchExisting(objectID)
|
||||
@@ -61,7 +59,6 @@ public extension CoreStore {
|
||||
- parameter objects: an array of `NSManagedObject`s created/fetched outside the `DataStack`
|
||||
- returns: the `NSManagedObject` array for objects that exists in the `DataStack`
|
||||
*/
|
||||
@warn_unused_result
|
||||
public static func fetchExisting<T: NSManagedObject, S: Sequence where S.Iterator.Element == T>(_ objects: S) -> [T] {
|
||||
|
||||
return self.defaultStack.fetchExisting(objects)
|
||||
@@ -73,7 +70,6 @@ public extension CoreStore {
|
||||
- parameter objectIDs: the `NSManagedObjectID` array for the objects
|
||||
- returns: the `NSManagedObject` array for objects that exists in the `DataStack`
|
||||
*/
|
||||
@warn_unused_result
|
||||
public static func fetchExisting<T: NSManagedObject, S: Sequence where S.Iterator.Element == NSManagedObjectID>(_ objectIDs: S) -> [T] {
|
||||
|
||||
return self.defaultStack.fetchExisting(objectIDs)
|
||||
@@ -86,7 +82,6 @@ public extension CoreStore {
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: the first `NSManagedObject` instance that satisfies the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public static func fetchOne<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> T? {
|
||||
|
||||
return self.defaultStack.fetchOne(from, fetchClauses)
|
||||
@@ -99,7 +94,6 @@ public extension CoreStore {
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: the first `NSManagedObject` instance that satisfies the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public static func fetchOne<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> T? {
|
||||
|
||||
return self.defaultStack.fetchOne(from, fetchClauses)
|
||||
@@ -112,7 +106,6 @@ public extension CoreStore {
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: all `NSManagedObject` instances that satisfy the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public static func fetchAll<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [T]? {
|
||||
|
||||
return self.defaultStack.fetchAll(from, fetchClauses)
|
||||
@@ -125,7 +118,6 @@ public extension CoreStore {
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: all `NSManagedObject` instances that satisfy the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public static func fetchAll<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [T]? {
|
||||
|
||||
return self.defaultStack.fetchAll(from, fetchClauses)
|
||||
@@ -138,7 +130,6 @@ public extension CoreStore {
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: the number `NSManagedObject`s that satisfy the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public static func fetchCount<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> Int? {
|
||||
|
||||
return self.defaultStack.fetchCount(from, fetchClauses)
|
||||
@@ -151,7 +142,6 @@ public extension CoreStore {
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: the number `NSManagedObject`s that satisfy the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public static func fetchCount<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> Int? {
|
||||
|
||||
return self.defaultStack.fetchCount(from, fetchClauses)
|
||||
@@ -164,7 +154,6 @@ 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 `NSManagedObject` that satisfies the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public static func fetchObjectID<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> NSManagedObjectID? {
|
||||
|
||||
return self.defaultStack.fetchObjectID(from, fetchClauses)
|
||||
@@ -177,7 +166,6 @@ 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 `NSManagedObject` that satisfies the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public static func fetchObjectID<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? {
|
||||
|
||||
return self.defaultStack.fetchObjectID(from, fetchClauses)
|
||||
@@ -190,7 +178,6 @@ 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 `NSManagedObject`s that satisfy the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public static func fetchObjectIDs<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? {
|
||||
|
||||
return self.defaultStack.fetchObjectIDs(from, fetchClauses)
|
||||
@@ -203,7 +190,6 @@ 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 `NSManagedObject`s that satisfy the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public static func fetchObjectIDs<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? {
|
||||
|
||||
return self.defaultStack.fetchObjectIDs(from, fetchClauses)
|
||||
@@ -219,7 +205,6 @@ 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<U>` parameter.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public static func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
||||
|
||||
return self.defaultStack.queryValue(from, selectClause, queryClauses)
|
||||
@@ -235,7 +220,6 @@ 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<U>` parameter.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public static func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
||||
|
||||
return self.defaultStack.queryValue(from, selectClause, queryClauses)
|
||||
@@ -251,7 +235,6 @@ 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<U>` parameter.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public static func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[NSString: AnyObject]]? {
|
||||
|
||||
return self.defaultStack.queryAttributes(from, selectClause, queryClauses)
|
||||
@@ -267,7 +250,6 @@ 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<U>` parameter.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public static func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[NSString: AnyObject]]? {
|
||||
|
||||
return self.defaultStack.queryAttributes(from, selectClause, queryClauses)
|
||||
|
||||
@@ -40,7 +40,6 @@ public extension DataStack {
|
||||
- parameter object: a reference to the object created/fetched outside the `DataStack`
|
||||
- returns: the `NSManagedObject` instance if the object exists in the `DataStack`, or `nil` if not found.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchExisting<T: NSManagedObject>(_ object: T) -> T? {
|
||||
|
||||
do {
|
||||
@@ -59,7 +58,6 @@ public extension DataStack {
|
||||
- parameter objectID: the `NSManagedObjectID` for the object
|
||||
- returns: the `NSManagedObject` instance if the object exists in the `DataStack`, or `nil` if not found.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchExisting<T: NSManagedObject>(_ objectID: NSManagedObjectID) -> T? {
|
||||
|
||||
do {
|
||||
@@ -78,7 +76,6 @@ public extension DataStack {
|
||||
- parameter objects: an array of `NSManagedObject`s created/fetched outside the `DataStack`
|
||||
- returns: the `NSManagedObject` array for objects that exists in the `DataStack`
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchExisting<T: NSManagedObject, S: Sequence where S.Iterator.Element == T>(_ objects: S) -> [T] {
|
||||
|
||||
return objects.flatMap { (try? self.mainContext.existingObject(with: $0.objectID)) as? T }
|
||||
@@ -90,7 +87,6 @@ public extension DataStack {
|
||||
- parameter objectIDs: the `NSManagedObjectID` array for the objects
|
||||
- returns: the `NSManagedObject` array for objects that exists in the `DataStack`
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchExisting<T: NSManagedObject, S: Sequence where S.Iterator.Element == NSManagedObjectID>(_ objectIDs: S) -> [T] {
|
||||
|
||||
return objectIDs.flatMap { (try? self.mainContext.existingObject(with: $0)) as? T }
|
||||
@@ -103,7 +99,6 @@ public extension DataStack {
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: the first `NSManagedObject` instance that satisfies the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchOne<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> T? {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -120,7 +115,6 @@ public extension DataStack {
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: the first `NSManagedObject` instance that satisfies the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchOne<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> T? {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -137,7 +131,6 @@ public extension DataStack {
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: all `NSManagedObject` instances that satisfy the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchAll<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [T]? {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -154,7 +147,6 @@ public extension DataStack {
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: all `NSManagedObject` instances that satisfy the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchAll<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [T]? {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -171,7 +163,6 @@ public extension DataStack {
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: the number `NSManagedObject`s that satisfy the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchCount<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> Int? {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -188,7 +179,6 @@ public extension DataStack {
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: the number `NSManagedObject`s that satisfy the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchCount<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> Int? {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -205,7 +195,6 @@ public extension DataStack {
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: the `NSManagedObjectID` for the first `NSManagedObject` that satisfies the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchObjectID<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> NSManagedObjectID? {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -222,7 +211,6 @@ public extension DataStack {
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: the `NSManagedObjectID` for the first `NSManagedObject` that satisfies the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchObjectID<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -239,7 +227,6 @@ public extension DataStack {
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: the `NSManagedObjectID` for all `NSManagedObject`s that satisfy the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchObjectIDs<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -256,7 +243,6 @@ public extension DataStack {
|
||||
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
|
||||
- returns: the `NSManagedObjectID` for all `NSManagedObject`s that satisfy the specified `FetchClause`s
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func fetchObjectIDs<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -276,7 +262,6 @@ public extension DataStack {
|
||||
- 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<U>` parameter.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -296,7 +281,6 @@ public extension DataStack {
|
||||
- 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<U>` parameter.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -316,7 +300,6 @@ public extension DataStack {
|
||||
- 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<U>` parameter.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[NSString: AnyObject]]? {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -336,7 +319,6 @@ public extension DataStack {
|
||||
- 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<U>` parameter.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[NSString: AnyObject]]? {
|
||||
|
||||
CoreStore.assert(
|
||||
|
||||
Reference in New Issue
Block a user