swift - Swift 下划线方法和函数有什么作用?

标签 swift built-in

在尝试使用 Swift 时,我发现了很多有用的方法和函数,它们都带有下划线前缀。例如,字符串有一个隐藏的 _split() 方法。由于某些原因,函数 _sin()_cos()(但不是 _tan_sqrt)也可用默认情况下。事实上,REPL 实际上建议我在键入 sin(2.0) 时使用这些函数。我没有导入 Foundation 或任何导入 Foundation 的内容。

为什么 Swift 提供这些“隐藏”函数,尤其是三角函数,我原以为它们是数学模块的一部分而不是内置函数。

最佳答案

Things beginning with underscores are not for public consumption and only exposed publicly for internal reasons (e.g. for testing because the standard library can't use @testable).

By Dave Abrahams

关于swift - Swift 下划线方法和函数有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40685231/

相关文章:

ios - 解决中心崩溃报告中的执行顺序错误

c - gcc __builtin_expect 似乎没有生成正确的代码

Python - os.path 不存在 : AttributeError: 'module' object has no attribute 'path'

python - 在 python 中子类化内置枚举

Python 使用 return 语句中列表中的内置所有函数

facebook - 在 Swift 中使 UIView 成为一个圆圈

ios - 关闭 presentingviewController 后显示警报

Swift 三个双引号

function - 如何避免codeigniter中的sql注入(inject)

swift - 快速导航 Controller 行为