swift - 我如何在 Swift 中解释这个缩短版本的代码?

标签 swift

我知道 UIAlertController 上的 preferredStyle 属性采用 UIAlertControllerStyleAlertUIAlertControllerStyleActionSheet。当我看到下面的示例时,它似乎可以通过使用 .Alert 或 .ActionSheet 来缩短。我试图弄清楚这个快捷方式的技术术语,以便我可以更好地向其他人解释它的用法,如果有更好的方法,我不想说“使用带点的缩短版本”。非常感谢。

缩短

let actionSheetController: UIAlertController = UIAlertController(title: "title", message: "message", preferredStyle: .ActionSheet)

常规

let actionSheetController: UIAlertController = UIAlertController(title: "title", message: "message", preferredStyle: UIAlertControllerStyleActionSheet)

最佳答案

这是来自 The Swift Programming Language > Language Guide > Enumerations 的引述> 枚举语法:

Once directionToHead is declared as a CompassPoint, you can set it to a different CompassPoint value using a shorter dot syntax:

directionToHead = .East

老实说,称它为“短点语法”可能是向其他人解释它的最清晰的方式。

但如果您想听起来令人困惑,这里引用自 The Swift Programming Language > Language Reference > Expressions > 隐式成员表达式:

An implicit member expression is an abbreviated way to access a member of a type, such as an enumeration case or a type method, in a context where type inference can determine the implied type. It has the following form:

.member name

关于swift - 我如何在 Swift 中解释这个缩短版本的代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33718261/

相关文章:

ios - 在 Collection View 中显示两个不同的单元格 - Swift 2.0 iOS

ios - 如何获得另一个 NSDate 当天特定时间的 NSDate 表示?

ios - 将用户默认设置添加到暗模式

ios - 在 Swift 中设置 AVCaptureSession 中 AVCaptureDevice 的低帧率

ios - 如何将文本文件用作数据库?

ios - 如何获取具有最大 ID 的项目?

swift - 如何在 Swift 中编辑字典中的值

ios - CloudKit 记录类型继承

ios - 如何一次只允许一个UIImageView被触摸

ios - RxDataSources 和改变模型的能力