Swift: How to call non-class function if I have the same function in my class? [duplicate]

半世苍凉 提交于 2019-12-25 07:47:02

问题


I know that I can just change names, but is there another way to solve this?

class MyClass{
    func print(_ string: String) {
        // I'm trying to call a native print method.
        // Results in error, because it's trying to do recursion.
        print(string, terminator: ";")
    }
}

回答1:


For global Swift builtins you can call Swift.whatever(argument), so in this case:

Swift.print(string, terminator: ";")


来源:https://stackoverflow.com/questions/42559175/swift-how-to-call-non-class-function-if-i-have-the-same-function-in-my-class

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!