mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-28 04:11:47 +01:00
WIP: broken generics
This commit is contained in:
@@ -316,7 +316,7 @@ 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.
|
||||
*/
|
||||
public func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[NSString: AnyObject]]? {
|
||||
public func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
@@ -336,7 +336,7 @@ 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.
|
||||
*/
|
||||
public func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[NSString: AnyObject]]? {
|
||||
public func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
|
||||
@@ -115,10 +115,10 @@ public struct OrderBy: FetchClause, QueryClause, DeleteClause, Hashable {
|
||||
switch sortKey {
|
||||
|
||||
case .ascending(let keyPath):
|
||||
return SortDescriptor(key: keyPath, ascending: true)
|
||||
return NSSortDescriptor(key: keyPath, ascending: true)
|
||||
|
||||
case .descending(let keyPath):
|
||||
return SortDescriptor(key: keyPath, ascending: false)
|
||||
return NSSortDescriptor(key: keyPath, ascending: false)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -44,7 +44,7 @@ public protocol SelectValueResultType: SelectResultType {
|
||||
|
||||
static var attributeType: NSAttributeType { get }
|
||||
|
||||
static func fromResultObject(_ result: AnyObject) -> Self?
|
||||
static func fromResultObject(_ result: Any) -> Self?
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ public protocol SelectValueResultType: SelectResultType {
|
||||
*/
|
||||
public protocol SelectAttributesResultType: SelectResultType {
|
||||
|
||||
static func fromResultObjects(_ result: [AnyObject]) -> [[NSString: AnyObject]]
|
||||
static func fromResultObjects(_ result: [Any]) -> [[String: Any]]
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
|
||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "average(<attributeName>)" is used
|
||||
- returns: a `SelectTerm` to a `Select` clause for querying the average value of an attribute
|
||||
*/
|
||||
public static func average(_ keyPath: KeyPath, As alias: KeyPath? = nil) -> SelectTerm {
|
||||
public static func average(_ keyPath: KeyPath, as alias: KeyPath? = nil) -> SelectTerm {
|
||||
|
||||
return ._aggregate(
|
||||
function: "average:",
|
||||
@@ -125,7 +125,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
|
||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "count(<attributeName>)" is used
|
||||
- returns: a `SelectTerm` to a `Select` clause for a count query
|
||||
*/
|
||||
public static func count(_ keyPath: KeyPath, As alias: KeyPath? = nil) -> SelectTerm {
|
||||
public static func count(_ keyPath: KeyPath, as alias: KeyPath? = nil) -> SelectTerm {
|
||||
|
||||
return ._aggregate(
|
||||
function: "count:",
|
||||
@@ -147,7 +147,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
|
||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "max(<attributeName>)" is used
|
||||
- returns: a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute
|
||||
*/
|
||||
public static func maximum(_ keyPath: KeyPath, As alias: KeyPath? = nil) -> SelectTerm {
|
||||
public static func maximum(_ keyPath: KeyPath, as alias: KeyPath? = nil) -> SelectTerm {
|
||||
|
||||
return ._aggregate(
|
||||
function: "max:",
|
||||
@@ -169,7 +169,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
|
||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "min(<attributeName>)" is used
|
||||
- returns: a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute
|
||||
*/
|
||||
public static func minimum(_ keyPath: KeyPath, As alias: KeyPath? = nil) -> SelectTerm {
|
||||
public static func minimum(_ keyPath: KeyPath, as alias: KeyPath? = nil) -> SelectTerm {
|
||||
|
||||
return ._aggregate(
|
||||
function: "min:",
|
||||
@@ -191,7 +191,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
|
||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "sum(<attributeName>)" is used
|
||||
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
|
||||
*/
|
||||
public static func sum(_ keyPath: KeyPath, As alias: KeyPath? = nil) -> SelectTerm {
|
||||
public static func sum(_ keyPath: KeyPath, as alias: KeyPath? = nil) -> SelectTerm {
|
||||
|
||||
return ._aggregate(
|
||||
function: "sum:",
|
||||
@@ -214,7 +214,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
|
||||
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "objecID" is used
|
||||
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
|
||||
*/
|
||||
public static func objectID(As alias: KeyPath? = nil) -> SelectTerm {
|
||||
public static func objectID(as alias: KeyPath? = nil) -> SelectTerm {
|
||||
|
||||
return ._identity(
|
||||
alias: alias ?? "objectID",
|
||||
@@ -402,7 +402,7 @@ extension Bool: SelectValueResultType {
|
||||
return .booleanAttributeType
|
||||
}
|
||||
|
||||
public static func fromResultObject(_ result: AnyObject) -> Bool? {
|
||||
public static func fromResultObject(_ result: Any) -> Bool? {
|
||||
switch result {
|
||||
|
||||
case let decimal as NSDecimalNumber:
|
||||
@@ -429,7 +429,7 @@ extension Int8: SelectValueResultType {
|
||||
return .integer64AttributeType
|
||||
}
|
||||
|
||||
public static func fromResultObject(_ result: AnyObject) -> Int8? {
|
||||
public static func fromResultObject(_ result: Any) -> Int8? {
|
||||
|
||||
guard let value = (result as? NSNumber)?.int64Value else {
|
||||
|
||||
@@ -449,7 +449,7 @@ extension Int16: SelectValueResultType {
|
||||
return .integer64AttributeType
|
||||
}
|
||||
|
||||
public static func fromResultObject(_ result: AnyObject) -> Int16? {
|
||||
public static func fromResultObject(_ result: Any) -> Int16? {
|
||||
|
||||
guard let value = (result as? NSNumber)?.int64Value else {
|
||||
|
||||
@@ -469,7 +469,7 @@ extension Int32: SelectValueResultType {
|
||||
return .integer64AttributeType
|
||||
}
|
||||
|
||||
public static func fromResultObject(_ result: AnyObject) -> Int32? {
|
||||
public static func fromResultObject(_ result: Any) -> Int32? {
|
||||
|
||||
guard let value = (result as? NSNumber)?.int64Value else {
|
||||
|
||||
@@ -489,7 +489,7 @@ extension Int64: SelectValueResultType {
|
||||
return .integer64AttributeType
|
||||
}
|
||||
|
||||
public static func fromResultObject(_ result: AnyObject) -> Int64? {
|
||||
public static func fromResultObject(_ result: Any) -> Int64? {
|
||||
|
||||
return (result as? NSNumber)?.int64Value
|
||||
}
|
||||
@@ -505,7 +505,7 @@ extension Int: SelectValueResultType {
|
||||
return .integer64AttributeType
|
||||
}
|
||||
|
||||
public static func fromResultObject(_ result: AnyObject) -> Int? {
|
||||
public static func fromResultObject(_ result: Any) -> Int? {
|
||||
|
||||
guard let value = (result as? NSNumber)?.int64Value else {
|
||||
|
||||
@@ -525,7 +525,7 @@ extension Double: SelectValueResultType {
|
||||
return .doubleAttributeType
|
||||
}
|
||||
|
||||
public static func fromResultObject(_ result: AnyObject) -> Double? {
|
||||
public static func fromResultObject(_ result: Any) -> Double? {
|
||||
|
||||
return (result as? NSNumber)?.doubleValue
|
||||
}
|
||||
@@ -541,7 +541,7 @@ extension Float: SelectValueResultType {
|
||||
return .floatAttributeType
|
||||
}
|
||||
|
||||
public static func fromResultObject(_ result: AnyObject) -> Float? {
|
||||
public static func fromResultObject(_ result: Any) -> Float? {
|
||||
|
||||
return (result as? NSNumber)?.floatValue
|
||||
}
|
||||
@@ -557,7 +557,7 @@ extension String: SelectValueResultType {
|
||||
return .stringAttributeType
|
||||
}
|
||||
|
||||
public static func fromResultObject(_ result: AnyObject) -> String? {
|
||||
public static func fromResultObject(_ result: Any) -> String? {
|
||||
|
||||
return result as? String
|
||||
}
|
||||
@@ -573,7 +573,7 @@ extension Date: SelectValueResultType {
|
||||
return .dateAttributeType
|
||||
}
|
||||
|
||||
public static func fromResultObject(_ result: AnyObject) -> Date? {
|
||||
public static func fromResultObject(_ result: Any) -> Date? {
|
||||
|
||||
return result as? Date
|
||||
}
|
||||
@@ -589,7 +589,7 @@ extension Data: SelectValueResultType {
|
||||
return .binaryDataAttributeType
|
||||
}
|
||||
|
||||
public static func fromResultObject(_ result: AnyObject) -> Data? {
|
||||
public static func fromResultObject(_ result: Any) -> Data? {
|
||||
|
||||
return result as? Data
|
||||
}
|
||||
@@ -605,9 +605,9 @@ extension NSNumber: SelectValueResultType {
|
||||
return .integer64AttributeType
|
||||
}
|
||||
|
||||
public class func fromResultObject(_ result: AnyObject) -> Self? {
|
||||
public class func fromResultObject(_ result: Any) -> Self? {
|
||||
|
||||
func forceCast<T: NSNumber>(_ object: AnyObject) -> T? {
|
||||
func forceCast<T: NSNumber>(_ object: Any) -> T? {
|
||||
|
||||
return (object as? T)
|
||||
}
|
||||
@@ -625,9 +625,9 @@ extension NSString: SelectValueResultType {
|
||||
return .stringAttributeType
|
||||
}
|
||||
|
||||
public class func fromResultObject(_ result: AnyObject) -> Self? {
|
||||
public class func fromResultObject(_ result: Any) -> Self? {
|
||||
|
||||
func forceCast<T: NSString>(_ object: AnyObject) -> T? {
|
||||
func forceCast<T: NSString>(_ object: Any) -> T? {
|
||||
|
||||
return (object as? T)
|
||||
}
|
||||
@@ -645,9 +645,9 @@ extension NSDecimalNumber {
|
||||
return .decimalAttributeType
|
||||
}
|
||||
|
||||
public override class func fromResultObject(_ result: AnyObject) -> Self? {
|
||||
public override class func fromResultObject(_ result: Any) -> Self? {
|
||||
|
||||
func forceCast<T: NSDecimalNumber>(_ object: AnyObject) -> T? {
|
||||
func forceCast<T: NSDecimalNumber>(_ object: Any) -> T? {
|
||||
|
||||
return (object as? T)
|
||||
}
|
||||
@@ -665,9 +665,9 @@ extension NSDate: SelectValueResultType {
|
||||
return .dateAttributeType
|
||||
}
|
||||
|
||||
public class func fromResultObject(_ result: AnyObject) -> Self? {
|
||||
public class func fromResultObject(_ result: Any) -> Self? {
|
||||
|
||||
func forceCast<T: NSDate>(_ object: AnyObject) -> T? {
|
||||
func forceCast<T: NSDate>(_ object: Any) -> T? {
|
||||
|
||||
return (object as? T)
|
||||
}
|
||||
@@ -685,9 +685,9 @@ extension NSData: SelectValueResultType {
|
||||
return .binaryDataAttributeType
|
||||
}
|
||||
|
||||
public class func fromResultObject(_ result: AnyObject) -> Self? {
|
||||
public class func fromResultObject(_ result: Any) -> Self? {
|
||||
|
||||
func forceCast<T: NSData>(_ object: AnyObject) -> T? {
|
||||
func forceCast<T: NSData>(_ object: Any) -> T? {
|
||||
|
||||
return (object as? T)
|
||||
}
|
||||
@@ -705,9 +705,9 @@ extension NSManagedObjectID: SelectValueResultType {
|
||||
return .objectIDAttributeType
|
||||
}
|
||||
|
||||
public class func fromResultObject(_ result: AnyObject) -> Self? {
|
||||
public class func fromResultObject(_ result: Any) -> Self? {
|
||||
|
||||
func forceCast<T: NSManagedObjectID>(_ object: AnyObject) -> T? {
|
||||
func forceCast<T: NSManagedObjectID>(_ object: Any) -> T? {
|
||||
|
||||
return (object as? T)
|
||||
}
|
||||
@@ -722,9 +722,9 @@ extension NSDictionary: SelectAttributesResultType {
|
||||
|
||||
// MARK: SelectAttributesResultType
|
||||
|
||||
public class func fromResultObjects(_ result: [AnyObject]) -> [[NSString: AnyObject]] {
|
||||
public class func fromResultObjects(_ result: [Any]) -> [[String: Any]] {
|
||||
|
||||
return result as! [[NSString: AnyObject]]
|
||||
return result as! [[String: Any]]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -761,7 +761,7 @@ internal extension Collection where Iterator.Element == SelectTerm {
|
||||
}
|
||||
}
|
||||
|
||||
var propertiesToFetch = [AnyObject]()
|
||||
var propertiesToFetch = [Any]()
|
||||
for term in self {
|
||||
|
||||
switch term {
|
||||
|
||||
@@ -79,7 +79,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
|
||||
- parameter format: the format string for the predicate
|
||||
- parameter args: the arguments for `format`
|
||||
*/
|
||||
public init(_ format: String, _ args: NSObject...) {
|
||||
public init(_ format: String, _ args: Any...) {
|
||||
|
||||
self.init(NSPredicate(format: format, argumentArray: args))
|
||||
}
|
||||
@@ -90,7 +90,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
|
||||
- parameter format: the format string for the predicate
|
||||
- parameter argumentArray: the arguments for `format`
|
||||
*/
|
||||
public init(_ format: String, argumentArray: [NSObject]?) {
|
||||
public init(_ format: String, argumentArray: [Any]?) {
|
||||
|
||||
self.init(NSPredicate(format: format, argumentArray: argumentArray))
|
||||
}
|
||||
@@ -101,7 +101,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
|
||||
- parameter keyPath: the keyPath to compare with
|
||||
- parameter value: the arguments for the `==` operator
|
||||
*/
|
||||
public init(_ keyPath: KeyPath, isEqualTo value: NSObject?) {
|
||||
public init(_ keyPath: KeyPath, isEqualTo value: Any?) {
|
||||
|
||||
self.init(value == nil
|
||||
? NSPredicate(format: "\(keyPath) == nil")
|
||||
@@ -114,7 +114,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
|
||||
- parameter keyPath: the keyPath to compare with
|
||||
- parameter list: the array to check membership of
|
||||
*/
|
||||
public init(_ keyPath: KeyPath, isMemberOf list: [NSObject]) {
|
||||
public init(_ keyPath: KeyPath, isMemberOf list: [Any]) {
|
||||
|
||||
self.init(NSPredicate(format: "\(keyPath) IN %@", list))
|
||||
}
|
||||
@@ -125,7 +125,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
|
||||
- parameter keyPath: the keyPath to compare with
|
||||
- parameter list: the sequence to check membership of
|
||||
*/
|
||||
public init<S: Sequence>(_ keyPath: KeyPath, isMemberOf list: S) where S.Iterator.Element: NSObject {
|
||||
public init<S: Sequence>(_ keyPath: KeyPath, isMemberOf list: S) where S.Iterator.Element: Any {
|
||||
|
||||
self.init(NSPredicate(format: "\(keyPath) IN %@", Array(list) as NSArray))
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ public extension CoreStore {
|
||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||
*/
|
||||
public static func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[NSString: AnyObject]]? {
|
||||
public static func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? {
|
||||
|
||||
return self.defaultStack.queryAttributes(from, selectClause, queryClauses)
|
||||
}
|
||||
@@ -250,7 +250,7 @@ public extension CoreStore {
|
||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||
*/
|
||||
public static func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[NSString: AnyObject]]? {
|
||||
public static func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? {
|
||||
|
||||
return self.defaultStack.queryAttributes(from, selectClause, queryClauses)
|
||||
}
|
||||
|
||||
@@ -297,7 +297,7 @@ 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.
|
||||
*/
|
||||
public func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[NSString: AnyObject]]? {
|
||||
public func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? {
|
||||
|
||||
CoreStore.assert(
|
||||
Thread.isMainThread,
|
||||
@@ -316,7 +316,7 @@ 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.
|
||||
*/
|
||||
public func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[NSString: AnyObject]]? {
|
||||
public func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? {
|
||||
|
||||
CoreStore.assert(
|
||||
Thread.isMainThread,
|
||||
|
||||
Reference in New Issue
Block a user