I have defined a method on Float called printme , and when I try to call it using an integer literal, Swift does not find the method:
extension Float { func printme() { print("value: \(self)") } } 12.printme() // error: value of type 'Int' has no member 'printme'
If I use an explicit action, it works:
(12 as Float).printme() // prints "value: 12.0"
Why, if Float conforms to the IntegerLiteralConvertible protocol, 12.printme() cannot find the method on Float ? It works if the type is Double , but does not execute for Int32 , UInt and other types. Why does this work for Double , but not for Float ?
Please note that the following works:
func printit(f: Float) { print("value: \(f)") } printit(10) // prints "value: 10.0"
Thus, it fails when the method is called in an integer literal, but not when the integer literal is a parameter of the function.
In Xcode 6.4, it does not work differently:
12.printme() // error: cannot invoke 'printme' with no arguments
swift
vacawama
source share