prototype new Fields as propertyWrappers (Swift 5.2 above only)

This commit is contained in:
John Estropia
2020-01-15 18:29:58 +09:00
parent 5e37ee4566
commit 43f61359da
33 changed files with 1796 additions and 337 deletions

View File

@@ -26,6 +26,88 @@
import CoreData
import Foundation
// MARK: - FieldContainer.Value
extension FieldContainer.Stored {
/**
Creates a `Where` clause by comparing if a property is equal to a value
```
let person = dataStack.fetchOne(From<Person>().where({ $0.nickname == "John" }))
```
*/
public static func == (_ attribute: Self, _ value: V) -> Where<O> {
return Where(attribute.keyPath, isEqualTo: value)
}
/**
Creates a `Where` clause by comparing if a property is not equal to a value
```
let person = dataStack.fetchOne(From<Person>().where({ $0.nickname != "John" }))
```
*/
public static func != (_ attribute: Self, _ value: V) -> Where<O> {
return !Where(attribute.keyPath, isEqualTo: value)
}
/**
Creates a `Where` clause by comparing if a property is less than a value
```
let person = dataStack.fetchOne(From<Person>().where({ $0.age < 20 }))
```
*/
public static func < (_ attribute: Self, _ value: V) -> Where<O> {
return Where("%K < %@", attribute.keyPath, value.cs_toFieldStoredNativeType() as Any)
}
/**
Creates a `Where` clause by comparing if a property is greater than a value
```
let person = dataStack.fetchOne(From<Person>().where({ $0.age > 20 }))
```
*/
public static func > (_ attribute: Self, _ value: V) -> Where<O> {
return Where("%K > %@", attribute.keyPath, value.cs_toFieldStoredNativeType() as Any)
}
/**
Creates a `Where` clause by comparing if a property is less than or equal to a value
```
let person = dataStack.fetchOne(From<Person>().where({ $0.age <= 20 }))
```
*/
public static func <= (_ attribute: Self, _ value: V) -> Where<O> {
return Where("%K <= %@", attribute.keyPath, value.cs_toFieldStoredNativeType() as Any)
}
/**
Creates a `Where` clause by comparing if a property is greater than or equal to a value
```
let person = dataStack.fetchOne(From<Person>().where({ $0.age >= 20 }))
```
*/
public static func >= (_ attribute: Self, _ value: V) -> Where<O> {
return Where("%K >= %@", attribute.keyPath, value.cs_toFieldStoredNativeType() as Any)
}
/**
Creates a `Where` clause by checking if a sequence contains the value of a property
```
let dog = dataStack.fetchOne(From<Dog>().where({ ["Pluto", "Snoopy", "Scooby"] ~= $0.nickname }))
```
*/
public static func ~= <S: Sequence>(_ sequence: S, _ attribute: Self) -> Where<O> where S.Iterator.Element == V {
return Where(attribute.keyPath, isMemberOf: sequence)
}
}
// MARK: - ValueContainer.Required
extension ValueContainer.Required {