gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 05:35:48 26 4
gpt4 key购买 nike

在尝试使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com