如何仅在其他 属性 存在时调用具有条件绑定的方法

How to call a method with conditional binding only if other property exists

所以我想知道如果 other 属性 在一个衬里中不为零,是否可以调用在条件绑定中使用 other 属性 的方法。

像这样的伪代码:

if let foo = method(prop), bar = prop {
   // do something with foo
}

仅当 prop 不为 nil 时才会调用 method(prop):

if let prop = prop, let foo = method(prop) {
    // do something with foo
}

一个解决方案是使用地图:

if let foo = prop.map({ method([=10=]) }) {
     // ...
}