mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-31 06:33:06 +02:00
changed keyPath string utility to use String initializer
This commit is contained in:
@@ -27,67 +27,6 @@ import CoreData
|
||||
import Foundation
|
||||
|
||||
|
||||
// MARK: - DynamicObject
|
||||
|
||||
public extension DynamicObject where Self: CoreStoreObject {
|
||||
|
||||
/**
|
||||
Extracts the keyPath string from a `CoreStoreObject.Value` property.
|
||||
```
|
||||
let keyPath: String = Person.keyPath { $0.nickname }
|
||||
```
|
||||
*/
|
||||
public static func keyPath<O, V>(_ attribute: (Self) -> ValueContainer<O>.Required<V>) -> String {
|
||||
|
||||
return attribute(self.meta).keyPath
|
||||
}
|
||||
|
||||
/**
|
||||
Extracts the keyPath string from a `CoreStoreObject.Value` property.
|
||||
```
|
||||
let keyPath: String = Person.keyPath { $0.nickname }
|
||||
```
|
||||
*/
|
||||
public static func keyPath<O, V>(_ attribute: (Self) -> ValueContainer<O>.Optional<V>) -> String {
|
||||
|
||||
return attribute(self.meta).keyPath
|
||||
}
|
||||
|
||||
/**
|
||||
Extracts the keyPath string from a `CoreStoreObject.Relationship` property.
|
||||
```
|
||||
let keyPath: String = Person.keyPath { $0.pets }
|
||||
```
|
||||
*/
|
||||
public static func keyPath<O, D>(_ relationship: (Self) -> RelationshipContainer<O>.ToOne<D>) -> String {
|
||||
|
||||
return relationship(self.meta).keyPath
|
||||
}
|
||||
|
||||
/**
|
||||
Extracts the keyPath string from a `CoreStoreObject.Relationship` property.
|
||||
```
|
||||
let keyPath: String = Person.keyPath { $0.pets }
|
||||
```
|
||||
*/
|
||||
public static func keyPath<O, D>(_ relationship: (Self) -> RelationshipContainer<O>.ToManyOrdered<D>) -> String {
|
||||
|
||||
return relationship(self.meta).keyPath
|
||||
}
|
||||
|
||||
/**
|
||||
Extracts the keyPath string from a `CoreStoreObject.Relationship` property.
|
||||
```
|
||||
let keyPath: String = Person.keyPath { $0.pets }
|
||||
```
|
||||
*/
|
||||
public static func keyPath<O, D>(_ relationship: (Self) -> RelationshipContainer<O>.ToManyUnordered<D>) -> String {
|
||||
|
||||
return relationship(self.meta).keyPath
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - ValueContainer.Required
|
||||
|
||||
public extension ValueContainer.Required {
|
||||
@@ -98,7 +37,6 @@ public extension ValueContainer.Required {
|
||||
let person = CoreStore.fetchOne(From<Person>().where({ $0.nickname == "John" }))
|
||||
```
|
||||
*/
|
||||
@inline(__always)
|
||||
public static func == (_ attribute: ValueContainer<O>.Required<V>, _ value: V) -> Where<O> {
|
||||
|
||||
return Where(attribute.keyPath, isEqualTo: value)
|
||||
@@ -110,7 +48,6 @@ public extension ValueContainer.Required {
|
||||
let person = CoreStore.fetchOne(From<Person>().where({ $0.nickname != "John" }))
|
||||
```
|
||||
*/
|
||||
@inline(__always)
|
||||
public static func != (_ attribute: ValueContainer<O>.Required<V>, _ value: V) -> Where<O> {
|
||||
|
||||
return !Where(attribute.keyPath, isEqualTo: value)
|
||||
@@ -122,7 +59,6 @@ public extension ValueContainer.Required {
|
||||
let person = CoreStore.fetchOne(From<Person>().where({ $0.age < 20 }))
|
||||
```
|
||||
*/
|
||||
@inline(__always)
|
||||
public static func < (_ attribute: ValueContainer<O>.Required<V>, _ value: V) -> Where<O> {
|
||||
|
||||
return Where("%K < %@", attribute.keyPath, value)
|
||||
@@ -134,7 +70,6 @@ public extension ValueContainer.Required {
|
||||
let person = CoreStore.fetchOne(From<Person>().where({ $0.age > 20 }))
|
||||
```
|
||||
*/
|
||||
@inline(__always)
|
||||
public static func > (_ attribute: ValueContainer<O>.Required<V>, _ value: V) -> Where<O> {
|
||||
|
||||
return Where("%K > %@", attribute.keyPath, value)
|
||||
@@ -146,7 +81,6 @@ public extension ValueContainer.Required {
|
||||
let person = CoreStore.fetchOne(From<Person>().where({ $0.age <= 20 }))
|
||||
```
|
||||
*/
|
||||
@inline(__always)
|
||||
public static func <= (_ attribute: ValueContainer<O>.Required<V>, _ value: V) -> Where<O> {
|
||||
|
||||
return Where("%K <= %@", attribute.keyPath, value)
|
||||
@@ -158,7 +92,6 @@ public extension ValueContainer.Required {
|
||||
let person = CoreStore.fetchOne(From<Person>().where({ $0.age >= 20 }))
|
||||
```
|
||||
*/
|
||||
@inline(__always)
|
||||
public static func >= (_ attribute: ValueContainer<O>.Required<V>, _ value: V) -> Where<O> {
|
||||
|
||||
return Where("%K >= %@", attribute.keyPath, value)
|
||||
@@ -170,7 +103,6 @@ public extension ValueContainer.Required {
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where({ ["Pluto", "Snoopy", "Scooby"] ~= $0.nickname }))
|
||||
```
|
||||
*/
|
||||
@inline(__always)
|
||||
public static func ~= <S: Sequence>(_ sequence: S, _ attribute: ValueContainer<O>.Required<V>) -> Where<O> where S.Iterator.Element == V {
|
||||
|
||||
return Where(attribute.keyPath, isMemberOf: sequence)
|
||||
@@ -188,7 +120,6 @@ public extension ValueContainer.Optional {
|
||||
let person = CoreStore.fetchOne(From<Person>().where({ $0.nickname == "John" }))
|
||||
```
|
||||
*/
|
||||
@inline(__always)
|
||||
public static func == (_ attribute: ValueContainer<O>.Optional<V>, _ value: V?) -> Where<O> {
|
||||
|
||||
return Where(attribute.keyPath, isEqualTo: value)
|
||||
@@ -200,7 +131,6 @@ public extension ValueContainer.Optional {
|
||||
let person = CoreStore.fetchOne(From<Person>().where({ $0.nickname != "John" }))
|
||||
```
|
||||
*/
|
||||
@inline(__always)
|
||||
public static func != (_ attribute: ValueContainer<O>.Optional<V>, _ value: V?) -> Where<O> {
|
||||
|
||||
return !Where(attribute.keyPath, isEqualTo: value)
|
||||
@@ -212,7 +142,6 @@ public extension ValueContainer.Optional {
|
||||
let person = CoreStore.fetchOne(From<Person>().where({ $0.age < 20 }))
|
||||
```
|
||||
*/
|
||||
@inline(__always)
|
||||
public static func < (_ attribute: ValueContainer<O>.Optional<V>, _ value: V?) -> Where<O> {
|
||||
|
||||
if let value = value {
|
||||
@@ -231,7 +160,6 @@ public extension ValueContainer.Optional {
|
||||
let person = CoreStore.fetchOne(From<Person>().where({ $0.age > 20 }))
|
||||
```
|
||||
*/
|
||||
@inline(__always)
|
||||
public static func > (_ attribute: ValueContainer<O>.Optional<V>, _ value: V?) -> Where<O> {
|
||||
|
||||
if let value = value {
|
||||
@@ -250,7 +178,6 @@ public extension ValueContainer.Optional {
|
||||
let person = CoreStore.fetchOne(From<Person>().where({ $0.age <= 20 }))
|
||||
```
|
||||
*/
|
||||
@inline(__always)
|
||||
public static func <= (_ attribute: ValueContainer<O>.Optional<V>, _ value: V?) -> Where<O> {
|
||||
|
||||
if let value = value {
|
||||
@@ -269,7 +196,6 @@ public extension ValueContainer.Optional {
|
||||
let person = CoreStore.fetchOne(From<Person>().where({ $0.age >= 20 }))
|
||||
```
|
||||
*/
|
||||
@inline(__always)
|
||||
public static func >= (_ attribute: ValueContainer<O>.Optional<V>, _ value: V?) -> Where<O> {
|
||||
|
||||
if let value = value {
|
||||
@@ -288,7 +214,6 @@ public extension ValueContainer.Optional {
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where({ ["Pluto", "Snoopy", "Scooby"] ~= $0.nickname }))
|
||||
```
|
||||
*/
|
||||
@inline(__always)
|
||||
public static func ~= <S: Sequence>(_ sequence: S, _ attribute: ValueContainer<O>.Optional<V>) -> Where<O> where S.Iterator.Element == V {
|
||||
|
||||
return Where(attribute.keyPath, isMemberOf: sequence)
|
||||
@@ -306,7 +231,6 @@ public extension RelationshipContainer.ToOne {
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where({ $0.master == me }))
|
||||
```
|
||||
*/
|
||||
@inline(__always)
|
||||
public static func == (_ relationship: RelationshipContainer<O>.ToOne<D>, _ object: D?) -> Where<O> {
|
||||
|
||||
return Where(relationship.keyPath, isEqualTo: object)
|
||||
@@ -318,7 +242,6 @@ public extension RelationshipContainer.ToOne {
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where({ $0.master != me }))
|
||||
```
|
||||
*/
|
||||
@inline(__always)
|
||||
public static func != (_ relationship: RelationshipContainer<O>.ToOne<D>, _ object: D?) -> Where<O> {
|
||||
|
||||
return !Where(relationship.keyPath, isEqualTo: object)
|
||||
@@ -330,7 +253,6 @@ public extension RelationshipContainer.ToOne {
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where({ [john, joe, bob] ~= $0.master }))
|
||||
```
|
||||
*/
|
||||
@inline(__always)
|
||||
public static func ~= <S: Sequence>(_ sequence: S, _ relationship: RelationshipContainer<O>.ToOne<D>) -> Where<O> where S.Iterator.Element == D {
|
||||
|
||||
return Where(relationship.keyPath, isMemberOf: sequence)
|
||||
@@ -342,6 +264,36 @@ public extension RelationshipContainer.ToOne {
|
||||
|
||||
extension DynamicObject where Self: CoreStoreObject {
|
||||
|
||||
@available(*, deprecated, message: "Use the String(keyPath:) initializer and pass the KeyPath: String(keyPath: \\Person.name)")
|
||||
public static func keyPath<O, V>(_ attribute: (Self) -> ValueContainer<O>.Required<V>) -> String {
|
||||
|
||||
return attribute(self.meta).keyPath
|
||||
}
|
||||
|
||||
@available(*, deprecated, message: "Use the String(keyPath:) initializer and pass the KeyPath: String(keyPath: \\Person.name)")
|
||||
public static func keyPath<O, V>(_ attribute: (Self) -> ValueContainer<O>.Optional<V>) -> String {
|
||||
|
||||
return attribute(self.meta).keyPath
|
||||
}
|
||||
|
||||
@available(*, deprecated, message: "Use the String(keyPath:) initializer and pass the KeyPath: String(keyPath: \\Person.friend)")
|
||||
public static func keyPath<O, D>(_ relationship: (Self) -> RelationshipContainer<O>.ToOne<D>) -> String {
|
||||
|
||||
return relationship(self.meta).keyPath
|
||||
}
|
||||
|
||||
@available(*, deprecated, message: "Use the String(keyPath:) initializer and pass the KeyPath: String(keyPath: \\Person.friends)")
|
||||
public static func keyPath<O, D>(_ relationship: (Self) -> RelationshipContainer<O>.ToManyOrdered<D>) -> String {
|
||||
|
||||
return relationship(self.meta).keyPath
|
||||
}
|
||||
|
||||
@available(*, deprecated, message: "Use the String(keyPath:) initializer and pass the KeyPath: String(keyPath: \\Person.friends)")
|
||||
public static func keyPath<O, D>(_ relationship: (Self) -> RelationshipContainer<O>.ToManyUnordered<D>) -> String {
|
||||
|
||||
return relationship(self.meta).keyPath
|
||||
}
|
||||
|
||||
@available(*, deprecated, message: "Use the Where<DynamicObject>(_:) initializer that accepts the same closure argument")
|
||||
public static func `where`(_ condition: (Self) -> Where<Self>) -> Where<Self> {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user