I think the error message is misleading. The real problem was how to interpret literal 1 in the second call. Swift defaults to Int when defining a variable:
let a = 1
But the compiler can read it as Double , UInt32 , CChar , etc. depending on context:
func takeADouble(value: Double) { ... } func takeAUInt(value: UInt) { ... } takeADouble(value: 1)
type(of:) is defined as a generic function:
func type<Type, Metatype>(of: Type) -> Metatype
The compiler has no idea how to interpret the general Type parameter: should it be Int , UInt , UInt16 , etc.? Here is the error I received from IBM Swift Sandbox:
Overloads for '==' exist with these partially matching parameter lists (Any.Type?, Any.Type?), (UInt8, UInt8), (Int8, Int8), (UInt16, UInt16), (Int16, Int16), (UInt32, UInt32), ...
You can give the coompiler some help by telling it what type it is:
type(of: 1 as Int) == Int.self
Code different
source share