I would like to create a Reactive extension to the UIButton which will take any object (value and reference type) and will enable the button based on the value. If it is nil I want to disable the button and enable if it there is value.
here is the code:
extension Reactive where Base: UIButton {
var isEnabledForModel: Binder<Any?> {
return Binder(base, binding: {
$0.isEnabled = $1 != nil
})
}
}
When I try to bind the observable which contains optional struct I get an error: Ambiguous reference to member 'bind(to: )
. Is there any way to pass Any
to the Binder or achieve it in different way? Maybe I want to make it too generic.