Method Selection in Swift
When I was growing up, methods were selected based solely on the stuff on the right side of the equals sign. Not so in Swift. Consider this example.
class ThingWithTwoSameNamedMethods {
func doIt() {
let h: Int = doIt()
print("thank you for calling outer doit \(h)")
}
func doIt() -> Int {
return 32
}
}
let _: Void = ThingWithTwoSameNamedMethods().doIt()
let someInt: Int = ThingWithTwoSameNamedMethods().doIt()
let sum = ThingWithTwoSameNamedMethods().doIt() + 4
If this doesn't scare you, it should, because like most things in Swift: if it's compiling, it's wonderful. But if it's not compiling, for any reason, method selection and typing information is just not there... and you cannot infer it.