mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-26 19:31:29 +01:00
add missing predicate operator overloads
This commit is contained in:
@@ -43,7 +43,7 @@ extension FieldContainer {
|
|||||||
@Field.Virtual("pluralName", customGetter: Animal.pluralName(_:))
|
@Field.Virtual("pluralName", customGetter: Animal.pluralName(_:))
|
||||||
var pluralName: String = ""
|
var pluralName: String = ""
|
||||||
|
|
||||||
@Field.PlistCoded("color")
|
@Field.Coded("color", coder: FieldCoders.Plist.self)
|
||||||
var color: UIColor?
|
var color: UIColor?
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ extension FieldContainer {
|
|||||||
@Field.Virtual("pluralName", customGetter: Animal.pluralName(_:))
|
@Field.Virtual("pluralName", customGetter: Animal.pluralName(_:))
|
||||||
var pluralName: String = ""
|
var pluralName: String = ""
|
||||||
|
|
||||||
@Field.PlistCoded("color")
|
@Field.Coded("color", coder: FieldCoders.Plist.self)
|
||||||
var color: UIColor?
|
var color: UIColor?
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -65,12 +65,7 @@ extension FieldContainer {
|
|||||||
@Field.Virtual(
|
@Field.Virtual(
|
||||||
"displayName",
|
"displayName",
|
||||||
customGetter: { (object, field) in
|
customGetter: { (object, field) in
|
||||||
if let cached = field.primitiveValue, !cached.isEmpty {
|
return "\(object.$title.value) \(object.$name.value)"
|
||||||
return cached
|
|
||||||
}
|
|
||||||
let value = "\(object.$title.value) \(object.$name.value)"
|
|
||||||
field.primitiveValue = value
|
|
||||||
return value
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
var displayName: String = ""
|
var displayName: String = ""
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ extension FieldContainer {
|
|||||||
@Field.Virtual("pluralName", customGetter: Animal.pluralName(_:))
|
@Field.Virtual("pluralName", customGetter: Animal.pluralName(_:))
|
||||||
var pluralName: String = ""
|
var pluralName: String = ""
|
||||||
|
|
||||||
@Field.PlistCoded("color")
|
@Field.Coded("color", coder: FieldCoders.Plist.self)
|
||||||
var color: UIColor?
|
var color: UIColor?
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ extension DynamicObject where Self: CoreStoreObject {
|
|||||||
@Field.Stored("nickname")
|
@Field.Stored("nickname")
|
||||||
var nickname: String?
|
var nickname: String?
|
||||||
|
|
||||||
@Field.PlistCoded("color")
|
@Field.Coded("color", coder: FieldCoders.Plist.self)
|
||||||
var color: UIColor?
|
var color: UIColor?
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -63,7 +63,7 @@ extension DynamicObject where Self: CoreStoreObject {
|
|||||||
@Field.Stored("nickname")
|
@Field.Stored("nickname")
|
||||||
var nickname: String?
|
var nickname: String?
|
||||||
|
|
||||||
@Field.PlistCoded("color")
|
@Field.Coded("color", coder: FieldCoders.Plist.self)
|
||||||
var color: UIColor?
|
var color: UIColor?
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -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
|
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> {
|
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)
|
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>
|
// MARK: - KeyPath where Root: CoreStoreObject, Value: ValueContainer<Root>.Required<QueryableAttributeType & Equatable>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user