magpoc magpoc - 2 years ago 62
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')

Answer Source

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()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download