我想开始使用 Swift 三元运算符,这样我就不会设置值,而是触发不同的函数。
if position.x < kWidth / 2 ? fireLeft() : fireRight()
这行不通,实际上我对此很满意。我该怎么做才能让它发挥作用?
最佳答案
三元运算符中不需要 if
关键字。
关于Swift 三元运算符函数调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34105109/
我想开始使用 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>'
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