【发布时间】:2018-05-15 07:53:17
【问题描述】:
我注意到 Swift 的一些编码示例以不同的方式声明可选属性。但是,我似乎很难区分它们(或者更确切地说,何时使用它们。)
class MyClass {
// I believe this can start as nil but should always be set
// once it is.
var optionalProperty1: Type!
// I believe this can be set or nil anytime.
var optionalProperty2: Type?
// I think this is the same as
// var optionalProperty3: Type!
lazy var optionalProperty3: Type
}
每一种与其他的有何不同?何时应该使用每一种?
【问题讨论】: