gpt4 book ai didi

swift - 下划线 "_"在 Swift 中是什么意思?

转载 作者:搜寻专家 更新时间:2023-10-31 08:27:09 25 4
gpt4 key购买 nike

我刚刚在浏览 Swift 模块头时发现了这个:

protocol _ObjectiveCBridgeable {

类似地:

protocol _SequenceType {

来自 Objective-C 背景,这对我来说似乎非常不合常规。下划线 _ 通常暗示相关实体是私有(private)的,并且通常在 header 可见性方面是隐藏的。为什么在 Swift 中它们是公开可见的? Swift 的命名约定是否发生了变化?

最佳答案

就 Swift 而言,约定似乎已经发生了变化,如下所示:

/// This protocol is an implementation detail of `SequenceType`; do
/// not use it directly.
///
/// Its requirements are inherited by `SequenceType` and thus must
/// be satisfied by types conforming to that protocol.
protocol _SequenceType {
}

如您所见,下划线 _ 现在似乎暗示相关实体是其逻辑子项的“实现细节”。

关于swift - 下划线 "_"在 Swift 中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28366121/

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