所以我想知道是否有可能调用在条件绑定中使用其他属性的方法,如果其他属性在一行中不是nil。
像这样的伪代码:
if let foo = method(prop), bar = prop {
// do something with foo
}
只有当prop不为nil时才会调用方法(prop):
if let prop = prop, let foo = method(prop) {
// do something with foo
}
一个解决方案是使用map:
if let foo = prop.map({ method($0) }) {
// ...
}