Swift 三元运算符函数调用?

标签 swift if-statement ternary

我想开始使用 Swift 三元运算符,这样我就不会设置值,而是触发不同的函数。

if position.x < kWidth / 2 ? fireLeft() : fireRight()

这行不通,实际上我对此很满意。我该怎么做才能让它发挥作用?

最佳答案

三元运算符中不需要 if 关键字。

关于Swift 三元运算符函数调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34105109/

相关文章:

Swift 结构扩展 : 'Cannot convert return expression of type <type> to return type <type>'

c - 如何简化复合否定逻辑

python - 确保用户在使用 BMI 分析器时只输入整数

c - 错误 : expression is not assignable ternary operator

swift - fatal error : Index Out of Range(UIPickerView)

ios - 如何使用 WatchConnectivity 在我的 iOS 和 Watch 应用程序之间共享信息?

excel - ……:mm:ss format causing IF statement to return False

jSTL - 在 JSTL 中更改为三元

javascript - wait 和三元运算符之间的优先级

swift:计时器(每秒)+gestureRecognizer 使 GUI 崩溃