This code is invalid:
both nest1 function can't coexist.
But they have a different signature: one is returning an int and the other a string.
Aren't functions with different signatures, supposed to be able to coexist?
Code Block func name1() { func nest1() -> Int { print("nest1") return 3 } func nest1() -> String { print("nest2") return "nest1" } }
both nest1 function can't coexist.
But they have a different signature: one is returning an int and the other a string.
Aren't functions with different signatures, supposed to be able to coexist?
YES, when the functions are global:Aren't functions with different signatures, supposed to be able to coexist?
Code Block func nest1() -> Int { print("nest1") return 3 } func nest1() -> String { print("nest2") return "nest1" }
Or they are methods:
Code Block class MyClass { func nest1() -> Int { print("nest1") return 3 } func nest1() -> String { print("nest2") return "nest1" } }
But, as for now, nested functions cannot be overloaded.
Your code may work in the future version of Swift:
Xcode 12.5 Beta 3 Release Notes
Please get the latest beta of Xcode 12.5 and try by yourself.Updates in Xcode 12.5 Beta
Swift
Resolved Issues
・Function overloading now works in local contexts, making the following valid:
...