gpt4 book ai didi

ios - 隐式成员表达式是用 Swift 编写的首选方式吗

转载 作者:搜寻专家 更新时间:2023-11-01 07:21:49 24 4
gpt4 key购买 nike

使用隐式成员表达式有好处吗?

来自Swift Docs :

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.

这方面的一个例子是:

let label = UILabel()
label.lineBreakMode = .ByTruncatingMiddle // NSLineBreakMode

let button = UIButton()
button.backgroundColor = .brownColor() // UIColor()

使用更长的版本是否被认为是多余的?使用隐式成员表达式是否有任何性能优势?还是纯粹是风格/个人喜好?

最佳答案

这两种风格都没有性能优势。

好的风格可能是尽可能使用隐式语法,除非省略类型名称会使代码困惑。

关于ios - 隐式成员表达式是用 Swift 编写的首选方式吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38516505/

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