I am using reflection to try to check if a struct has a nil value.
struct MyStruct {
let myString: String?
}
let properties = Mirror(reflecting: MyStruct(myString: nil)).children.filter { $0.label != nil }
for property in properties {
if property.value == nil { // value has type "Any" will always fail.
print("property \(property.label!) is nil")
}
}
How do I cast the Any type to Any?
Aucun commentaire:
Enregistrer un commentaire