Swift:如果我的类中有相同的函数,如何调用非类函数? [英] Swift: How to call non-class function if I have the same function in my class?

查看:24
本文介绍了Swift:如果我的类中有相同的函数,如何调用非类函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以更改名称,但还有其他方法可以解决这个问题吗?

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: ";")
    }
}

推荐答案

对于全局 Swift 内置函数,你可以调用 Swift.whatever(argument),所以在这种情况下:

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

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

这篇关于Swift:如果我的类中有相同的函数,如何调用非类函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆