下划线"_"代表什么?在Swift中是什么意思? [英] What does an underscore "_" mean in Swift?

查看:343
本文介绍了下划线"_"代表什么?在Swift中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在浏览Swift模块标题时发现的:

I just found this while browsing through the Swift module headers:

protocol _ObjectiveCBridgeable {

类似地:

protocol _SequenceType {

从Objective-C的背景来看,这在我看来非常不合常规.下划线_通常表示所关注的实体是私有的,并且通常在标头可见性方面是隐藏的.为什么在Swift中它们是公开可见的? Swift的命名约定是否已更改?

Coming from an Objective-C background, this seems highly unconventional to me. The underscore _ usually implies that the concerned entity is private, and is often hidden in terms of header visibility. Why is it that in Swift they are publicly visible? Have the naming conventions changed for Swift?

推荐答案

就Swift而言,惯例已经发生了变化,如下所示:

It seems that the conventions have changed as far as Swift is concerned, as evidenced by the following:

/// 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 {
}

如您所见,下划线_现在似乎暗示所关注的实体是其逻辑子级的实现细节".

As you can see, the underscore _ now seems to imply that the concerned entity is an 'implementation detail' of it's logical children.

这篇关于下划线"_"代表什么?在Swift中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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