我想知道是否存在与Swift中的选项相关的任何性能成本,例如,如果我们必须重复使用选项。请考虑以下两个代码片段 第一种方法
var f: Foo?
// foo returns an optional
if let anotherF = foo() {
f = anotherF
}
else {
f = Foo()
}
f?.doSomething()
f?.doSomethingElse()
f?.doAnotherThing()
// and so on
第二种方法
var f = Foo()
if let anotherF = foo() {
f = anotherF
}
f.doSomething()
f.doAnotherThing()
f.doAnotherThing()
// and so on
与第一种方法相比,第二种方法是否有任何性能优势