magpoc magpoc - 6 months ago 5x
Swift Question

Is there a way to call a global function within a class that has a method whose name is the same as the global function?

The code below gives an error because it tries to call the method of the class rather than a global function:

func a(i: Int) -> Int {
return i + 10

class B {
func a(s: String) -> String {
return s + "bbb"

func b() {
// Error (Cannot convert value of type 'Int' to expected argument type 'String')


Yup, there is. If you app's name were, for instance, "myApp", then you could call the global function, which has the same name and number of argument as the one in your class B, like so:

func b()