我在Objective-C中遇到了条件if语句:
self.frontCardView = self.backCardView;
if ((self.backCardView = [self popPersonViewWithFrame:[self backCardViewFrame]])) {
// Fade the back card into view.
...
}
基本上:
if ((self.backCardView = self.popPersonViewWithFrame(self.backCardViewFrame()))) {...}
这会将“ self.backCardView
”设置为“ ”的返回值-popPersonViewWithFrame:
。在C(和Objective-C)中,赋值的结果就是赋值。
在这种情况下,表达式“ (self.backCardView = [self popPersonViewWithFrame:self.backCardViewFrame])
”的结果为“ ”的返回值-popPersonViewWithFrame:
。
如果返回值为“ nil
”,则不执行条件语句(因为“ nil
”为false
值)。
如果我尝试在Swift中做同样的事情:
self.frontCardView = self.backCardView
if ((self.backCardView = self.popPersonViewWithFrame(self.backCardViewFrame()))) {
// Fade the back card into view.
...
}
我在编译时遇到错误:
类型'()'不符合协议'LogicValue'
分配,然后分别检查是否为零。
self.frontCardView = self.backCardView
self.backCardView = self.popPersonViewWithFrame(self.backCardViewFrame())
if self.backCardView != nil {
// Fade the back card into view.
// ...
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句