Swift三元语法错误 [英] Swift ternary syntax error
问题描述
我一直都在使用Objective-C编程,而我对Swift还是陌生的。这个错误Xcode让我感到非常困惑。
I used to program in Objective-C all the time and I am new to Swift. This error Xcode gives me really confuse me.
func renderBufferAreaBAUp(yOffset: CGFloat, amount: CGFloat, ifLeft: Bool)
{
var topViewIndexForIndexAdjust = ifLeft?leftTopIndex:rightTopIndex
}
在这行我打算使用三元。 leftTopIndex和rightTopIndex都是Int类型。但是Xcode给了我这行代码,
On this line I intended to use ternary. leftTopIndex and rightTopIndex are both Int type. However Xcode gives me those on this particular line,
行上的连续语句必须用';'
期望的表达式
Consecutive statements on a line must be separated by ';' Expected expression
有人可以告诉我这是什么意思吗?谢谢。
Can anybody tell me what those mean? Thanks.
推荐答案
迅速的错误消息通常是晦涩的,没有帮助。您的真正问题是Swift需要在?
和:
周围有一些空间。
Swift error messages are frequently cryptic and not helpful. Your real problem is that Swift needs some space around the ?
and :
.
var topViewIndexForIndexAdjust = ifLeft ? leftTopIndex : rightTopIndex
这篇关于Swift三元语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!