下面的代码给出了错误,因为它尝试调用类的方法而不是全局函数:
func a(i: Int) -> Int {
return i + 10
}
class B {
func a(s: String) -> String {
return s + "bbb"
}
func b() {
print(a(100))
// Error (Cannot convert value of type 'Int' to expected argument type 'String')
}
}
是的,有。如果您的应用程序名称为“ myApp”,则可以调用全局函数,该函数具有与类中的参数相同的名称和数量B
,例如:
func b()
{
print(myApp.a(100))
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句