wickwirew / Runtime

A Swift Runtime library for viewing type info, and the dynamic getting and setting of properties.
MIT License
1.08k stars 94 forks source link

Is it possible to Property Set to a nil value for an optional property? #86

Closed LittleCodingFox closed 3 years ago

LittleCodingFox commented 3 years ago

I'm setting a property but it seems that property.set doesn't accept nil values. In this case it's an Int?. What would I need to do to make Runtime support this?

wickwirew commented 3 years ago

The problem is that the underlying value type is not known. So when you do try property.set(value: nil, on: &value) the wrapped type in Optional<?> is ambiguous, and not all nils are the same. e.g. Optional<Int64?>.none has a different size than Optional<Int32?>.

You could just do try property.set(value: Optional<Int>.none, on: &value) to clear it up.