I got the following code:
let floatValue: Float = 1
let intValue: Int = 1
if floatValue == intValue {
println("Types and value are equal")
} else {
println("Type is not equal.")
}
I know that it will print "Type is not equal."
But i got an error at if floatValue == intValue
The error is:
Float is not convertible to 'MirrorDisposition'
I have never seen this error before and couldn't find anything about it. This code does run fine in xCode 6 beta 1, 2 and 3. I'm now running xCode 6 beta 4.
Does anyone know what this error means? And what I eventually can do about it.
MirrorDisposition
is one of the types you can get from a Mirror
of a value (using reflect
function). They are made for the IDE to enable displaying the values.
/// How children of this value should be presented in the IDE.
enum MirrorDisposition {
case Struct
case Class
case Enum
case Tuple
case Aggregate
case IndexContainer
case KeyContainer
case MembershipContainer
case Container
case Optional
case ObjCObject
}
The error message means that the compiler didn't find an ==
operator to compare a Float
with an Int
. However, it probably found an ==
operator for MirrorDisposition
and Int
, so it is trying to convert Float
to MirrorDisposition
but it obviously can't, so you get an error message.
(by the way, the type error you get is random, depending on the operator the compiler tries to use. I am getting Float is not convertible to Selector
).
The error message is a bug, there should be a message saying Could not find == operator for Float and Int
.
The obvious fix to check value equality is using a cast:
if intValue == Int(floatValue) {
There is no reason to compare types this way because in Swift, types are checked by the compiler. There should never be a reason to check the type explicitly (speaking about value types, not object types, of course).
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