I'm working with the Mirror
in swift, I found Mirror.Child
is very strange, the label is nullable, but the value seems not nullable.
public typealias Child = (label: String?, value: Any)
I don't know how to check if the value is nil or not.
let b: Bool? = true
let a: Any = b
print(a == nil) // false
I have one solution:
print(String(describing: a) == "nil") // true
but it is obviously not a good solution.
what is the best way to check if a
is nil or not ?
Let me put more detail,
let mirror = Mirror(reflecting: object) // object can be any object.
for child in mirror.children {
guard let label = child.label else {
continue
}
// how to check if the value is nil or not here ?
setValue(child.value, forKey: label)
}