mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-21 17:09:10 +01:00
WIP: rehaul of type-safe fetching and querying
This commit is contained in:
@@ -287,7 +287,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||
*/
|
||||
public func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
||||
public func queryValue<T: NSManagedObject, U: CoreStoreQueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
@@ -306,7 +306,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||
*/
|
||||
public func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
||||
public func queryValue<T: NSManagedObject, U: CoreStoreQueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
|
||||
@@ -32,31 +32,34 @@ import CoreData
|
||||
/**
|
||||
The `SelectResultType` protocol is implemented by return types supported by the `Select` clause.
|
||||
*/
|
||||
public protocol SelectResultType {}
|
||||
public protocol SelectResultType: CoreStoreQueryableAttributeType {
|
||||
|
||||
|
||||
// MARK: - SelectValueResultType
|
||||
|
||||
/**
|
||||
The `SelectValueResultType` protocol is implemented by return types supported by the `queryValue(...)` methods.
|
||||
*/
|
||||
public protocol SelectValueResultType: SelectResultType {
|
||||
|
||||
static var attributeType: NSAttributeType { get }
|
||||
|
||||
static func fromResultObject(_ result: Any) -> Self?
|
||||
}
|
||||
|
||||
|
||||
// MARK: - SelectAttributesResultType
|
||||
//// MARK: - SelectValueResultType
|
||||
//
|
||||
///**
|
||||
// The `SelectValueResultType` protocol is implemented by return types supported by the `queryValue(...)` methods.
|
||||
// */
|
||||
//public protocol SelectValueResultType: SelectResultType {
|
||||
//
|
||||
// static var attributeType: NSAttributeType { get }
|
||||
//
|
||||
// static func fromResultObject(_ result: Any) -> Self?
|
||||
//}
|
||||
|
||||
/**
|
||||
The `SelectValueResultType` protocol is implemented by return types supported by the `queryAttributes(...)` methods.
|
||||
*/
|
||||
public protocol SelectAttributesResultType: SelectResultType {
|
||||
|
||||
static func fromResultObjects(_ result: [Any]) -> [[String: Any]]
|
||||
}
|
||||
|
||||
//// MARK: - SelectAttributesResultType
|
||||
//
|
||||
///**
|
||||
// The `SelectValueResultType` protocol is implemented by return types supported by the `queryAttributes(...)` methods.
|
||||
// */
|
||||
//public protocol SelectAttributesResultType: SelectResultType {
|
||||
//
|
||||
// static func fromResultObjects(_ result: [Any]) -> [[String: Any]]
|
||||
//}
|
||||
|
||||
|
||||
// MARK: - SelectTerm
|
||||
@@ -335,7 +338,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
|
||||
|
||||
- parameter sortDescriptors: a series of `NSSortDescriptor`s
|
||||
*/
|
||||
public struct Select<T: SelectResultType>: Hashable {
|
||||
public struct Select<T: CoreStoreQueryableAttributeType>: Hashable {
|
||||
|
||||
/**
|
||||
The `SelectResultType` type for the query's return value
|
||||
@@ -366,7 +369,7 @@ public struct Select<T: SelectResultType>: Hashable {
|
||||
|
||||
// MARK: Equatable
|
||||
|
||||
public static func == <T: SelectResultType, U: SelectResultType>(lhs: Select<T>, rhs: Select<U>) -> Bool {
|
||||
public static func == <T: CoreStoreQueryableAttributeType, U: CoreStoreQueryableAttributeType>(lhs: Select<T>, rhs: Select<U>) -> Bool {
|
||||
|
||||
return lhs.selectTerms == rhs.selectTerms
|
||||
}
|
||||
@@ -394,340 +397,340 @@ public extension Select where T: NSManagedObjectID {
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Bool: SelectValueResultType
|
||||
|
||||
extension Bool: SelectValueResultType {
|
||||
|
||||
public static var attributeType: NSAttributeType {
|
||||
|
||||
return .booleanAttributeType
|
||||
}
|
||||
|
||||
public static func fromResultObject(_ result: Any) -> Bool? {
|
||||
switch result {
|
||||
|
||||
case let decimal as NSDecimalNumber:
|
||||
// iOS: NSDecimalNumber(string: "0.5").boolValue // true
|
||||
// OSX: NSDecimalNumber(string: "0.5").boolValue // false
|
||||
return NSNumber(value: decimal.doubleValue).boolValue
|
||||
|
||||
case let number as NSNumber:
|
||||
return number.boolValue
|
||||
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Int8: SelectValueResultType
|
||||
|
||||
extension Int8: SelectValueResultType {
|
||||
|
||||
public static var attributeType: NSAttributeType {
|
||||
|
||||
return .integer64AttributeType
|
||||
}
|
||||
|
||||
public static func fromResultObject(_ result: Any) -> Int8? {
|
||||
|
||||
guard let value = (result as? NSNumber)?.int64Value else {
|
||||
|
||||
return nil
|
||||
}
|
||||
return numericCast(value) as Int8
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Int16: SelectValueResultType
|
||||
|
||||
extension Int16: SelectValueResultType {
|
||||
|
||||
public static var attributeType: NSAttributeType {
|
||||
|
||||
return .integer64AttributeType
|
||||
}
|
||||
|
||||
public static func fromResultObject(_ result: Any) -> Int16? {
|
||||
|
||||
guard let value = (result as? NSNumber)?.int64Value else {
|
||||
|
||||
return nil
|
||||
}
|
||||
return numericCast(value) as Int16
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Int32: SelectValueResultType
|
||||
|
||||
extension Int32: SelectValueResultType {
|
||||
|
||||
public static var attributeType: NSAttributeType {
|
||||
|
||||
return .integer64AttributeType
|
||||
}
|
||||
|
||||
public static func fromResultObject(_ result: Any) -> Int32? {
|
||||
|
||||
guard let value = (result as? NSNumber)?.int64Value else {
|
||||
|
||||
return nil
|
||||
}
|
||||
return numericCast(value) as Int32
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Int64: SelectValueResultType
|
||||
|
||||
extension Int64: SelectValueResultType {
|
||||
|
||||
public static var attributeType: NSAttributeType {
|
||||
|
||||
return .integer64AttributeType
|
||||
}
|
||||
|
||||
public static func fromResultObject(_ result: Any) -> Int64? {
|
||||
|
||||
return (result as? NSNumber)?.int64Value
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Int: SelectValueResultType
|
||||
|
||||
extension Int: SelectValueResultType {
|
||||
|
||||
public static var attributeType: NSAttributeType {
|
||||
|
||||
return .integer64AttributeType
|
||||
}
|
||||
|
||||
public static func fromResultObject(_ result: Any) -> Int? {
|
||||
|
||||
guard let value = (result as? NSNumber)?.int64Value else {
|
||||
|
||||
return nil
|
||||
}
|
||||
return numericCast(value) as Int
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Double : SelectValueResultType
|
||||
|
||||
extension Double: SelectValueResultType {
|
||||
|
||||
public static var attributeType: NSAttributeType {
|
||||
|
||||
return .doubleAttributeType
|
||||
}
|
||||
|
||||
public static func fromResultObject(_ result: Any) -> Double? {
|
||||
|
||||
return (result as? NSNumber)?.doubleValue
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Float: SelectValueResultType
|
||||
|
||||
extension Float: SelectValueResultType {
|
||||
|
||||
public static var attributeType: NSAttributeType {
|
||||
|
||||
return .floatAttributeType
|
||||
}
|
||||
|
||||
public static func fromResultObject(_ result: Any) -> Float? {
|
||||
|
||||
return (result as? NSNumber)?.floatValue
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - String: SelectValueResultType
|
||||
|
||||
extension String: SelectValueResultType {
|
||||
|
||||
public static var attributeType: NSAttributeType {
|
||||
|
||||
return .stringAttributeType
|
||||
}
|
||||
|
||||
public static func fromResultObject(_ result: Any) -> String? {
|
||||
|
||||
return result as? String
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Date: SelectValueResultType
|
||||
|
||||
extension Date: SelectValueResultType {
|
||||
|
||||
public static var attributeType: NSAttributeType {
|
||||
|
||||
return .dateAttributeType
|
||||
}
|
||||
|
||||
public static func fromResultObject(_ result: Any) -> Date? {
|
||||
|
||||
return result as? Date
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Data: SelectValueResultType
|
||||
|
||||
extension Data: SelectValueResultType {
|
||||
|
||||
public static var attributeType: NSAttributeType {
|
||||
|
||||
return .binaryDataAttributeType
|
||||
}
|
||||
|
||||
public static func fromResultObject(_ result: Any) -> Data? {
|
||||
|
||||
return result as? Data
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - NSNumber: SelectValueResultType
|
||||
|
||||
extension NSNumber: SelectValueResultType {
|
||||
|
||||
public class var attributeType: NSAttributeType {
|
||||
|
||||
return .integer64AttributeType
|
||||
}
|
||||
|
||||
public class func fromResultObject(_ result: Any) -> Self? {
|
||||
|
||||
func forceCast<T: NSNumber>(_ object: Any) -> T? {
|
||||
|
||||
return (object as? T)
|
||||
}
|
||||
return forceCast(result)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - NSString: SelectValueResultType
|
||||
|
||||
extension NSString: SelectValueResultType {
|
||||
|
||||
public class var attributeType: NSAttributeType {
|
||||
|
||||
return .stringAttributeType
|
||||
}
|
||||
|
||||
public class func fromResultObject(_ result: Any) -> Self? {
|
||||
|
||||
func forceCast<T: NSString>(_ object: Any) -> T? {
|
||||
|
||||
return (object as? T)
|
||||
}
|
||||
return forceCast(result)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - NSDecimalNumber: SelectValueResultType
|
||||
|
||||
extension NSDecimalNumber {
|
||||
|
||||
public override class var attributeType: NSAttributeType {
|
||||
|
||||
return .decimalAttributeType
|
||||
}
|
||||
|
||||
public override class func fromResultObject(_ result: Any) -> Self? {
|
||||
|
||||
func forceCast<T: NSDecimalNumber>(_ object: Any) -> T? {
|
||||
|
||||
return (object as? T)
|
||||
}
|
||||
return forceCast(result)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - NSDate: SelectValueResultType
|
||||
|
||||
extension NSDate: SelectValueResultType {
|
||||
|
||||
public static var attributeType: NSAttributeType {
|
||||
|
||||
return .dateAttributeType
|
||||
}
|
||||
|
||||
public class func fromResultObject(_ result: Any) -> Self? {
|
||||
|
||||
func forceCast<T: NSDate>(_ object: Any) -> T? {
|
||||
|
||||
return (object as? T)
|
||||
}
|
||||
return forceCast(result)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - NSData: SelectValueResultType
|
||||
|
||||
extension NSData: SelectValueResultType {
|
||||
|
||||
public static var attributeType: NSAttributeType {
|
||||
|
||||
return .binaryDataAttributeType
|
||||
}
|
||||
|
||||
public class func fromResultObject(_ result: Any) -> Self? {
|
||||
|
||||
func forceCast<T: NSData>(_ object: Any) -> T? {
|
||||
|
||||
return (object as? T)
|
||||
}
|
||||
return forceCast(result)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - NSManagedObjectID: SelectValueResultType
|
||||
|
||||
extension NSManagedObjectID: SelectValueResultType {
|
||||
|
||||
public class var attributeType: NSAttributeType {
|
||||
|
||||
return .objectIDAttributeType
|
||||
}
|
||||
|
||||
public class func fromResultObject(_ result: Any) -> Self? {
|
||||
|
||||
func forceCast<T: NSManagedObjectID>(_ object: Any) -> T? {
|
||||
|
||||
return (object as? T)
|
||||
}
|
||||
return forceCast(result)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - NSManagedObjectID: SelectAttributesResultType
|
||||
|
||||
extension NSDictionary: SelectAttributesResultType {
|
||||
|
||||
// MARK: SelectAttributesResultType
|
||||
|
||||
public class func fromResultObjects(_ result: [Any]) -> [[String: Any]] {
|
||||
|
||||
return result as! [[String: Any]]
|
||||
}
|
||||
}
|
||||
//// MARK: - Bool: SelectValueResultType
|
||||
//
|
||||
//extension Bool: SelectValueResultType {
|
||||
//
|
||||
// public static var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .booleanAttributeType
|
||||
// }
|
||||
//
|
||||
// public static func fromResultObject(_ result: Any) -> Bool? {
|
||||
// switch result {
|
||||
//
|
||||
// case let decimal as NSDecimalNumber:
|
||||
// // iOS: NSDecimalNumber(string: "0.5").boolValue // true
|
||||
// // OSX: NSDecimalNumber(string: "0.5").boolValue // false
|
||||
// return NSNumber(value: decimal.doubleValue).boolValue
|
||||
//
|
||||
// case let number as NSNumber:
|
||||
// return number.boolValue
|
||||
//
|
||||
// default:
|
||||
// return nil
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - Int8: SelectValueResultType
|
||||
//
|
||||
//extension Int8: SelectValueResultType {
|
||||
//
|
||||
// public static var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .integer64AttributeType
|
||||
// }
|
||||
//
|
||||
// public static func fromResultObject(_ result: Any) -> Int8? {
|
||||
//
|
||||
// guard let value = (result as? NSNumber)?.int64Value else {
|
||||
//
|
||||
// return nil
|
||||
// }
|
||||
// return numericCast(value) as Int8
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - Int16: SelectValueResultType
|
||||
//
|
||||
//extension Int16: SelectValueResultType {
|
||||
//
|
||||
// public static var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .integer64AttributeType
|
||||
// }
|
||||
//
|
||||
// public static func fromResultObject(_ result: Any) -> Int16? {
|
||||
//
|
||||
// guard let value = (result as? NSNumber)?.int64Value else {
|
||||
//
|
||||
// return nil
|
||||
// }
|
||||
// return numericCast(value) as Int16
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - Int32: SelectValueResultType
|
||||
//
|
||||
//extension Int32: SelectValueResultType {
|
||||
//
|
||||
// public static var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .integer64AttributeType
|
||||
// }
|
||||
//
|
||||
// public static func fromResultObject(_ result: Any) -> Int32? {
|
||||
//
|
||||
// guard let value = (result as? NSNumber)?.int64Value else {
|
||||
//
|
||||
// return nil
|
||||
// }
|
||||
// return numericCast(value) as Int32
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - Int64: SelectValueResultType
|
||||
//
|
||||
//extension Int64: SelectValueResultType {
|
||||
//
|
||||
// public static var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .integer64AttributeType
|
||||
// }
|
||||
//
|
||||
// public static func fromResultObject(_ result: Any) -> Int64? {
|
||||
//
|
||||
// return (result as? NSNumber)?.int64Value
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - Int: SelectValueResultType
|
||||
//
|
||||
//extension Int: SelectValueResultType {
|
||||
//
|
||||
// public static var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .integer64AttributeType
|
||||
// }
|
||||
//
|
||||
// public static func fromResultObject(_ result: Any) -> Int? {
|
||||
//
|
||||
// guard let value = (result as? NSNumber)?.int64Value else {
|
||||
//
|
||||
// return nil
|
||||
// }
|
||||
// return numericCast(value) as Int
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - Double : SelectValueResultType
|
||||
//
|
||||
//extension Double: SelectValueResultType {
|
||||
//
|
||||
// public static var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .doubleAttributeType
|
||||
// }
|
||||
//
|
||||
// public static func fromResultObject(_ result: Any) -> Double? {
|
||||
//
|
||||
// return (result as? NSNumber)?.doubleValue
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - Float: SelectValueResultType
|
||||
//
|
||||
//extension Float: SelectValueResultType {
|
||||
//
|
||||
// public static var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .floatAttributeType
|
||||
// }
|
||||
//
|
||||
// public static func fromResultObject(_ result: Any) -> Float? {
|
||||
//
|
||||
// return (result as? NSNumber)?.floatValue
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - String: SelectValueResultType
|
||||
//
|
||||
//extension String: SelectValueResultType {
|
||||
//
|
||||
// public static var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .stringAttributeType
|
||||
// }
|
||||
//
|
||||
// public static func fromResultObject(_ result: Any) -> String? {
|
||||
//
|
||||
// return result as? String
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - Date: SelectValueResultType
|
||||
//
|
||||
//extension Date: SelectValueResultType {
|
||||
//
|
||||
// public static var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .dateAttributeType
|
||||
// }
|
||||
//
|
||||
// public static func fromResultObject(_ result: Any) -> Date? {
|
||||
//
|
||||
// return result as? Date
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - Data: SelectValueResultType
|
||||
//
|
||||
//extension Data: SelectValueResultType {
|
||||
//
|
||||
// public static var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .binaryDataAttributeType
|
||||
// }
|
||||
//
|
||||
// public static func fromResultObject(_ result: Any) -> Data? {
|
||||
//
|
||||
// return result as? Data
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - NSNumber: SelectValueResultType
|
||||
//
|
||||
//extension NSNumber: SelectValueResultType {
|
||||
//
|
||||
// public class var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .integer64AttributeType
|
||||
// }
|
||||
//
|
||||
// public class func fromResultObject(_ result: Any) -> Self? {
|
||||
//
|
||||
// func forceCast<T: NSNumber>(_ object: Any) -> T? {
|
||||
//
|
||||
// return (object as? T)
|
||||
// }
|
||||
// return forceCast(result)
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - NSString: SelectValueResultType
|
||||
//
|
||||
//extension NSString: SelectValueResultType {
|
||||
//
|
||||
// public class var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .stringAttributeType
|
||||
// }
|
||||
//
|
||||
// public class func fromResultObject(_ result: Any) -> Self? {
|
||||
//
|
||||
// func forceCast<T: NSString>(_ object: Any) -> T? {
|
||||
//
|
||||
// return (object as? T)
|
||||
// }
|
||||
// return forceCast(result)
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - NSDecimalNumber: SelectValueResultType
|
||||
//
|
||||
//extension NSDecimalNumber {
|
||||
//
|
||||
// public override class var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .decimalAttributeType
|
||||
// }
|
||||
//
|
||||
// public override class func fromResultObject(_ result: Any) -> Self? {
|
||||
//
|
||||
// func forceCast<T: NSDecimalNumber>(_ object: Any) -> T? {
|
||||
//
|
||||
// return (object as? T)
|
||||
// }
|
||||
// return forceCast(result)
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - NSDate: SelectValueResultType
|
||||
//
|
||||
//extension NSDate: SelectValueResultType {
|
||||
//
|
||||
// public static var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .dateAttributeType
|
||||
// }
|
||||
//
|
||||
// public class func fromResultObject(_ result: Any) -> Self? {
|
||||
//
|
||||
// func forceCast<T: NSDate>(_ object: Any) -> T? {
|
||||
//
|
||||
// return (object as? T)
|
||||
// }
|
||||
// return forceCast(result)
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - NSData: SelectValueResultType
|
||||
//
|
||||
//extension NSData: SelectValueResultType {
|
||||
//
|
||||
// public static var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .binaryDataAttributeType
|
||||
// }
|
||||
//
|
||||
// public class func fromResultObject(_ result: Any) -> Self? {
|
||||
//
|
||||
// func forceCast<T: NSData>(_ object: Any) -> T? {
|
||||
//
|
||||
// return (object as? T)
|
||||
// }
|
||||
// return forceCast(result)
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - NSManagedObjectID: SelectValueResultType
|
||||
//
|
||||
//extension NSManagedObjectID: SelectValueResultType {
|
||||
//
|
||||
// public class var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .objectIDAttributeType
|
||||
// }
|
||||
//
|
||||
// public class func fromResultObject(_ result: Any) -> Self? {
|
||||
//
|
||||
// func forceCast<T: NSManagedObjectID>(_ object: Any) -> T? {
|
||||
//
|
||||
// return (object as? T)
|
||||
// }
|
||||
// return forceCast(result)
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - NSManagedObjectID: SelectAttributesResultType
|
||||
//
|
||||
//extension NSDictionary: SelectAttributesResultType {
|
||||
//
|
||||
// // MARK: SelectAttributesResultType
|
||||
//
|
||||
// public class func fromResultObjects(_ result: [Any]) -> [[String: Any]] {
|
||||
//
|
||||
// return result as! [[String: Any]]
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
// MARK: - Internal
|
||||
|
||||
@@ -205,7 +205,7 @@ public extension CoreStore {
|
||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||
*/
|
||||
public static func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
||||
public static func queryValue<T: NSManagedObject, U: CoreStoreQueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
||||
|
||||
return self.defaultStack.queryValue(from, selectClause, queryClauses)
|
||||
}
|
||||
@@ -220,7 +220,7 @@ public extension CoreStore {
|
||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||
*/
|
||||
public static func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
||||
public static func queryValue<T: NSManagedObject, U: CoreStoreQueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
||||
|
||||
return self.defaultStack.queryValue(from, selectClause, queryClauses)
|
||||
}
|
||||
|
||||
@@ -34,21 +34,30 @@ public protocol CoreStoreQueryableAttributeType: Hashable {
|
||||
|
||||
associatedtype QueryableNativeType: CoreDataNativeType
|
||||
|
||||
static var cs_rawAttributeType: NSAttributeType { get }
|
||||
|
||||
@inline(__always)
|
||||
static func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self?
|
||||
|
||||
@inline(__always)
|
||||
func cs_toQueryableNativeType() -> QueryableNativeType
|
||||
}
|
||||
|
||||
|
||||
// MARK: - NSManagedObject
|
||||
|
||||
extension NSManagedObject: CoreStoreQueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSManagedObjectID
|
||||
|
||||
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
||||
|
||||
return self.objectID
|
||||
}
|
||||
}
|
||||
//// MARK: - NSManagedObject
|
||||
//
|
||||
//extension NSManagedObject: CoreStoreQueryableAttributeType {
|
||||
//
|
||||
// public typealias QueryableNativeType = NSManagedObjectID
|
||||
//
|
||||
// public static let cs_rawAttributeType: NSAttributeType = .objectIDAttributeType
|
||||
//
|
||||
// @inline(__always)
|
||||
// public func cs_toQueryableNativeType() -> QueryableNativeType {
|
||||
//
|
||||
// return self.objectID
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
// MARK: - NSManagedObjectID
|
||||
@@ -57,6 +66,19 @@ extension NSManagedObjectID: CoreStoreQueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSManagedObjectID
|
||||
|
||||
public static let cs_rawAttributeType: NSAttributeType = .objectIDAttributeType
|
||||
|
||||
@nonobjc @inline(__always)
|
||||
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
|
||||
|
||||
func forceCast<T: NSManagedObjectID>(_ value: Any) -> T? {
|
||||
|
||||
return value as? T
|
||||
}
|
||||
return forceCast(value)
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
||||
|
||||
return self
|
||||
@@ -70,6 +92,21 @@ extension NSNumber: CoreStoreQueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSNumber
|
||||
|
||||
public class var cs_rawAttributeType: NSAttributeType {
|
||||
|
||||
return .integer64AttributeType
|
||||
}
|
||||
|
||||
@nonobjc @inline(__always)
|
||||
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
|
||||
|
||||
func forceCast<T: NSNumber>(_ value: Any) -> T? {
|
||||
|
||||
return value as? T
|
||||
}
|
||||
return forceCast(value)
|
||||
}
|
||||
|
||||
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
||||
|
||||
return self
|
||||
@@ -77,12 +114,36 @@ extension NSNumber: CoreStoreQueryableAttributeType {
|
||||
}
|
||||
|
||||
|
||||
// MARK: - NSNumber
|
||||
|
||||
extension NSDecimalNumber /*: CoreStoreQueryableAttributeType */ {
|
||||
|
||||
public override class var cs_rawAttributeType: NSAttributeType {
|
||||
|
||||
return .decimalAttributeType
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - NSString
|
||||
|
||||
extension NSString: CoreStoreQueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSString
|
||||
|
||||
public static let cs_rawAttributeType: NSAttributeType = .stringAttributeType
|
||||
|
||||
@nonobjc @inline(__always)
|
||||
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
|
||||
|
||||
func forceCast<T: NSString>(_ value: Any) -> T? {
|
||||
|
||||
return value as? T
|
||||
}
|
||||
return forceCast(value)
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
||||
|
||||
return self
|
||||
@@ -96,6 +157,19 @@ extension NSDate: CoreStoreQueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSDate
|
||||
|
||||
public static let cs_rawAttributeType: NSAttributeType = .dateAttributeType
|
||||
|
||||
@nonobjc @inline(__always)
|
||||
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
|
||||
|
||||
func forceCast<T: NSDate>(_ value: Any) -> T? {
|
||||
|
||||
return value as? T
|
||||
}
|
||||
return forceCast(value)
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
||||
|
||||
return self
|
||||
@@ -109,6 +183,19 @@ extension NSData: CoreStoreQueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSData
|
||||
|
||||
public static let cs_rawAttributeType: NSAttributeType = .binaryDataAttributeType
|
||||
|
||||
@nonobjc @inline(__always)
|
||||
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
|
||||
|
||||
func forceCast<T: NSData>(_ value: Any) -> T? {
|
||||
|
||||
return value as? T
|
||||
}
|
||||
return forceCast(value)
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
||||
|
||||
return self
|
||||
@@ -122,6 +209,24 @@ extension Bool: CoreStoreQueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSNumber
|
||||
|
||||
public static let cs_rawAttributeType: NSAttributeType = .booleanAttributeType
|
||||
|
||||
@inline(__always)
|
||||
public static func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Bool? {
|
||||
|
||||
switch value {
|
||||
|
||||
case let decimal as NSDecimalNumber:
|
||||
// iOS: NSDecimalNumber(string: "0.5").boolValue // true
|
||||
// OSX: NSDecimalNumber(string: "0.5").boolValue // false
|
||||
return NSNumber(value: decimal.doubleValue).boolValue
|
||||
|
||||
default:
|
||||
return value.boolValue
|
||||
}
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
||||
|
||||
return self as NSNumber
|
||||
@@ -135,6 +240,15 @@ extension Int16: CoreStoreQueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSNumber
|
||||
|
||||
public static let cs_rawAttributeType: NSAttributeType = .integer16AttributeType
|
||||
|
||||
@inline(__always)
|
||||
public static func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Int16? {
|
||||
|
||||
return value.int16Value
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
||||
|
||||
return self as NSNumber
|
||||
@@ -148,6 +262,15 @@ extension Int32: CoreStoreQueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSNumber
|
||||
|
||||
public static let cs_rawAttributeType: NSAttributeType = .integer32AttributeType
|
||||
|
||||
@inline(__always)
|
||||
public static func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Int32? {
|
||||
|
||||
return value.int32Value
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
||||
|
||||
return self as NSNumber
|
||||
@@ -161,6 +284,15 @@ extension Int64: CoreStoreQueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSNumber
|
||||
|
||||
public static let cs_rawAttributeType: NSAttributeType = .integer64AttributeType
|
||||
|
||||
@inline(__always)
|
||||
public static func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Int64? {
|
||||
|
||||
return value.int64Value
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
||||
|
||||
return self as NSNumber
|
||||
@@ -174,6 +306,15 @@ extension Int: CoreStoreQueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSNumber
|
||||
|
||||
public static let cs_rawAttributeType: NSAttributeType = .integer64AttributeType
|
||||
|
||||
@inline(__always)
|
||||
public static func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Int? {
|
||||
|
||||
return value.intValue
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
||||
|
||||
return self as NSNumber
|
||||
@@ -187,6 +328,15 @@ extension Double: CoreStoreQueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSNumber
|
||||
|
||||
public static let cs_rawAttributeType: NSAttributeType = .doubleAttributeType
|
||||
|
||||
@inline(__always)
|
||||
public static func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Double? {
|
||||
|
||||
return value.doubleValue
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
||||
|
||||
return self as NSNumber
|
||||
@@ -200,6 +350,15 @@ extension Float: CoreStoreQueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSNumber
|
||||
|
||||
public static let cs_rawAttributeType: NSAttributeType = .floatAttributeType
|
||||
|
||||
@inline(__always)
|
||||
public static func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Float? {
|
||||
|
||||
return value.floatValue
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
||||
|
||||
return self as NSNumber
|
||||
@@ -213,6 +372,15 @@ extension CGFloat: CoreStoreQueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSNumber
|
||||
|
||||
public static let cs_rawAttributeType: NSAttributeType = .doubleAttributeType
|
||||
|
||||
@inline(__always)
|
||||
public static func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> CGFloat? {
|
||||
|
||||
return CGFloat(value.doubleValue)
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
||||
|
||||
return self as NSNumber
|
||||
@@ -226,6 +394,15 @@ extension Date: CoreStoreQueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSDate
|
||||
|
||||
public static let cs_rawAttributeType: NSAttributeType = .dateAttributeType
|
||||
|
||||
@inline(__always)
|
||||
public static func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Date? {
|
||||
|
||||
return value as Date
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
||||
|
||||
return self as NSDate
|
||||
@@ -239,6 +416,15 @@ extension String: CoreStoreQueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSString
|
||||
|
||||
public static let cs_rawAttributeType: NSAttributeType = .stringAttributeType
|
||||
|
||||
@inline(__always)
|
||||
public static func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> String? {
|
||||
|
||||
return value as String
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
||||
|
||||
return self as NSString
|
||||
@@ -252,6 +438,15 @@ extension Data: CoreStoreQueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSData
|
||||
|
||||
public static let cs_rawAttributeType: NSAttributeType = .binaryDataAttributeType
|
||||
|
||||
@inline(__always)
|
||||
public static func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Data? {
|
||||
|
||||
return value as Data
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
||||
|
||||
return self as NSData
|
||||
@@ -265,6 +460,15 @@ extension NSNull: CoreStoreQueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSNull
|
||||
|
||||
public static let cs_rawAttributeType: NSAttributeType = .undefinedAttributeType
|
||||
|
||||
@inline(__always)
|
||||
public static func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
|
||||
|
||||
return self.init()
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
||||
|
||||
return self
|
||||
|
||||
@@ -250,7 +250,7 @@ extension DataStack: FetchableSource, QueryableSource {
|
||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||
*/
|
||||
public func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
||||
public func queryValue<T: NSManagedObject, U: CoreStoreQueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
||||
|
||||
CoreStore.assert(
|
||||
Thread.isMainThread,
|
||||
@@ -269,7 +269,7 @@ extension DataStack: FetchableSource, QueryableSource {
|
||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||
*/
|
||||
public func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
||||
public func queryValue<T: NSManagedObject, U: CoreStoreQueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
||||
|
||||
CoreStore.assert(
|
||||
Thread.isMainThread,
|
||||
|
||||
@@ -44,7 +44,7 @@ public protocol QueryableSource: class {
|
||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||
*/
|
||||
func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U?
|
||||
func queryValue<T: NSManagedObject, U: CoreStoreQueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U?
|
||||
|
||||
/**
|
||||
Queries aggregate values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
@@ -56,7 +56,7 @@ public protocol QueryableSource: class {
|
||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||
*/
|
||||
func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U?
|
||||
func queryValue<T: NSManagedObject, U: CoreStoreQueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U?
|
||||
|
||||
/**
|
||||
Queries a dictionary of attribute values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
|
||||
@@ -152,7 +152,16 @@ extension Bool: CoreStoreImportableAttributeType {
|
||||
@inline(__always)
|
||||
public static func cs_fromImportableNativeType(_ value: ImportableNativeType) -> Bool? {
|
||||
|
||||
return value.boolValue
|
||||
switch value {
|
||||
|
||||
case let decimal as NSDecimalNumber:
|
||||
// iOS: NSDecimalNumber(string: "0.5").boolValue // true
|
||||
// OSX: NSDecimalNumber(string: "0.5").boolValue // false
|
||||
return NSNumber(value: decimal.doubleValue).boolValue
|
||||
|
||||
default:
|
||||
return value.boolValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -238,13 +238,13 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
||||
// MARK: QueryableSource
|
||||
|
||||
@nonobjc
|
||||
public func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
||||
public func queryValue<T: NSManagedObject, U: CoreStoreQueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
||||
|
||||
return self.queryValue(from, selectClause, queryClauses)
|
||||
}
|
||||
|
||||
@nonobjc
|
||||
public func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
||||
public func queryValue<T: NSManagedObject, U: CoreStoreQueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
||||
|
||||
let fetchRequest = CoreStoreFetchRequest()
|
||||
let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
||||
@@ -262,6 +262,30 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
||||
return self.queryValue(selectTerms, fetchRequest: fetchRequest)
|
||||
}
|
||||
|
||||
@nonobjc
|
||||
public func queryAttributes<T: NSManagedObject, U: CoreStoreQueryableAttributeType>(_ from: From<T>, _ selectClause: Select<[U]>, _ queryClauses: QueryClause...) -> [[String: Any]]? {
|
||||
|
||||
return self.queryAttributes(from, selectClause, queryClauses)
|
||||
}
|
||||
|
||||
@nonobjc
|
||||
public func queryAttributes<T: NSManagedObject, U: CoreStoreQueryableAttributeType>(_ from: From<T>, _ selectClause: Select<[U]>, _ queryClauses: [QueryClause]) -> [[String: Any]]? {
|
||||
|
||||
let fetchRequest = CoreStoreFetchRequest()
|
||||
let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
||||
|
||||
fetchRequest.fetchLimit = 0
|
||||
|
||||
selectClause.selectTerms.applyToFetchRequest(fetchRequest, owner: selectClause)
|
||||
queryClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
|
||||
|
||||
guard storeFound else {
|
||||
|
||||
return nil
|
||||
}
|
||||
return self.queryAttributes(fetchRequest)
|
||||
}
|
||||
|
||||
@nonobjc
|
||||
public func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? {
|
||||
|
||||
@@ -415,7 +439,7 @@ internal extension NSManagedObjectContext {
|
||||
// MARK: Querying
|
||||
|
||||
@nonobjc
|
||||
internal func queryValue<U: SelectValueResultType>(_ selectTerms: [SelectTerm], fetchRequest: NSFetchRequest<NSFetchRequestResult>) -> U? {
|
||||
internal func queryValue<U: CoreStoreQueryableAttributeType>(_ selectTerms: [SelectTerm], fetchRequest: NSFetchRequest<NSFetchRequestResult>) -> U? {
|
||||
|
||||
var fetchResults: [Any]?
|
||||
var fetchError: Error?
|
||||
@@ -433,9 +457,9 @@ internal extension NSManagedObjectContext {
|
||||
if let fetchResults = fetchResults {
|
||||
|
||||
if let rawResult = fetchResults.first as? NSDictionary,
|
||||
let rawObject = rawResult[selectTerms.keyPathForFirstSelectTerm()] {
|
||||
let rawObject = rawResult[selectTerms.keyPathForFirstSelectTerm()] as? U.QueryableNativeType {
|
||||
|
||||
return Select<U>.ReturnType.fromResultObject(rawObject)
|
||||
return U.cs_fromQueryableNativeType(rawObject)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user