func funny() -> Int {
return 1
}
func funny() -> String {
return "2"
}
let i: Int = funny()
let s: String = funny()
Is fine. Since Swift knows the return type required. However, it can’t infer
the type of:
let q = funny()
-- Howard.
> On 11 Oct 2017, at 4:36 am, C. Keith Ray via swift-us
You need to know that the NAME of a method or function isn't just outside the
parenthesis.
The name of
func IsTextEmpty(foo : String?) -> Bool?
is
"IsTextEmpty(foo:)"
and the name of
func IsTextEmpty(text : String?) -> Bool
is
"IsTextEmpty(text:)"
The argument labels ar
nope. it's the same as this example:
func funny() -> Int {
return 1
}
func funny() -> String {
return "2"
}
print(funny()) // the compiler doesn't know which one you want.
// the above doesn't compile.
// error: forloop.playground:8:1: error: ambiguous use of 'funny()'
You have to have some
2 down vote favorite
Original StackOverflow post:
https://stackoverflow.com/questions/46620311/overloading-methods-where-only-difference-is-optional-vs-non-optional-type
I was under the impression that swift can have overloaded methods that differ
only in the type of object that the methods return
Thank you Howard for you response! However, I have a follow-up question:
Why are UnsafeMutableBufferPointer methods which modify not the buffer pointer
itself, but only the pointed-to memory, mutating at all?
UnsafeMutable(Buffer)Pointer already have non-mutating subscript setters, which
means