How can you check if a type is Optional in Swift?
Let's say I have a variable of type PartialKeyPath, where:
struct Foo {
let bar: String
let baz: String?
}
typealias Property<Root> = (key: PartialKeyPath<Root>, value: Any?)
typealias Properties<Root> = [Property<Root>]
Now let's say that I repeat the property instance:
properties.forEach { prop in
let valueType1 = type(of: prop.key).valueType
let valueType2 = type(of: value)
...
How can I check here if valueType1 is Optional<valueType2>, or is it optional for any other flavor?
So far the only way to find me is really ugly ...
source
share