add missing predicate operator overloads

This commit is contained in:
John Estropia
2020-02-19 13:58:14 +09:00
parent 843adf21f7
commit 58629bc1df
5 changed files with 29 additions and 12 deletions

View File

@@ -43,7 +43,7 @@ extension FieldContainer {
@Field.Virtual("pluralName", customGetter: Animal.pluralName(_:))
var pluralName: String = ""
@Field.PlistCoded("color")
@Field.Coded("color", coder: FieldCoders.Plist.self)
var color: UIColor?
}
```

View File

@@ -43,7 +43,7 @@ extension FieldContainer {
@Field.Virtual("pluralName", customGetter: Animal.pluralName(_:))
var pluralName: String = ""
@Field.PlistCoded("color")
@Field.Coded("color", coder: FieldCoders.Plist.self)
var color: UIColor?
}
```
@@ -65,12 +65,7 @@ extension FieldContainer {
@Field.Virtual(
"displayName",
customGetter: { (object, field) in
if let cached = field.primitiveValue, !cached.isEmpty {
return cached
}
let value = "\(object.$title.value) \(object.$name.value)"
field.primitiveValue = value
return value
return "\(object.$title.value) \(object.$name.value)"
}
)
var displayName: String = ""

View File

@@ -43,7 +43,7 @@ extension FieldContainer {
@Field.Virtual("pluralName", customGetter: Animal.pluralName(_:))
var pluralName: String = ""
@Field.PlistCoded("color")
@Field.Coded("color", coder: FieldCoders.Plist.self)
var color: UIColor?
}
```

View File

@@ -41,7 +41,7 @@ extension DynamicObject where Self: CoreStoreObject {
@Field.Stored("nickname")
var nickname: String?
@Field.PlistCoded("color")
@Field.Coded("color", coder: FieldCoders.Plist.self)
var color: UIColor?
}
```
@@ -63,7 +63,7 @@ extension DynamicObject where Self: CoreStoreObject {
@Field.Stored("nickname")
var nickname: String?
@Field.PlistCoded("color")
@Field.Coded("color", coder: FieldCoders.Plist.self)
var color: UIColor?
}
```

View File

@@ -364,7 +364,7 @@ public func ~= <O: NSManagedObject, D: NSManagedObject, S: Sequence>(_ sequence:
/**
Creates a `Where` clause by comparing if a property is equal to a value
```
let person = dataStack.fetchOne(From<Person>().where(\.nickname == "John"))
let person = dataStack.fetchOne(From<Person>().where(\.$nickname == "John"))
```
*/
public func == <O, V>(_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>, _ value: V) -> Where<O> {
@@ -372,6 +372,28 @@ public func == <O, V>(_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>, _ valu
return Where<O>(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(\.$nickname != "John"))
```
*/
public func != <O, V>(_ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>, _ value: V) -> Where<O> {
return !Where<O>(keyPath, isEqualTo: value)
}
/**
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"] ~= \.nickname))
```
*/
public func ~= <O, V, S: Sequence>(_ sequence: S, _ keyPath: KeyPath<O, FieldContainer<O>.Stored<V>>) -> Where<O> where S.Iterator.Element == V {
return Where<O>(O.meta[keyPath: keyPath].keyPath, isMemberOf: sequence)
}
// MARK: - KeyPath where Root: CoreStoreObject, Value: ValueContainer<Root>.Required<QueryableAttributeType & Equatable>