I want to check if my sender is an Xyz-Object
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
let senderIsBonusProduct = sender is Xyz
but I get following error:
Could not find a user-defined conversion from type 'Int1' to type 'Bool'
The expression sender is Xyz
is returning a Bool
depending on if sender
is of type Xyz
. It appears that there is a compiler bug whereby sender is Xyz
is actually returning a Int1
that is not getting coerced internally to a Bool
.
A workaround is:
let bonus = (sender is Xyz ? true : false)
You can also change it to
if let senderOfTypeXYZ = sender as? Xyz {
// senderOfTypeXYZ is available with the expected type here
}
Workarounds aren't required anymore with the Beta 3 release and you can combine the is
operator with other logical operators.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With