This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum FilterValue { | |
case string(String) | |
case bool(Bool) | |
func matches(value: Any) -> Bool { | |
switch self { | |
case .string(let stringValue): | |
return (value as? String) == stringValue | |
case .bool(let boolValue): | |
return (value as? Bool) == boolValue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct MyStruct { | |
let name: String | |
let number: Int | |
var bool: Bool | |
} | |
let instance = MyStruct(name: "Korg", number: 1, bool: true) | |
// Referencing | |
let nameRef: KeyPath<MyStruct, String> = \MyStruct.name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Filter<Object> { | |
init<Type>(keyPath: KeyPath<Object, Type>, matcher: @escaping (Type) -> Bool) { | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Filter<Object> { | |
let keyPath: PartialKeyPath<Object> | |
let matcher: (Any) -> Bool | |
init<Type>(keyPath: KeyPath<Object, Type>, matcher: @escaping (Type) -> Bool) { | |
self.keyPath = keyPath | |
self.matcher = { value in | |
guard let typedValue = value as? Type else { return false } | |
return matcher(typedValue) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Filter<Object> { | |
let keyPath: PartialKeyPath<Object> | |
private let matcher: (Any) -> Bool | |
init<Type>(keyPath: KeyPath<Object, Type>, matcher: @escaping (Type) -> Bool) { | |
self.keyPath = keyPath | |
self.matcher = { value in | |
let typedValue = value as! Type | |
return matcher(typedValue) |
OlderNewer