Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift ternary syntax error

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
}

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.

like image 370
Bigman Avatar asked Dec 06 '25 02:12

Bigman


1 Answers

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
like image 141
vacawama Avatar answered Dec 08 '25 18:12

vacawama