Tung Mai Le Tung Mai Le - 3 months ago 7
Swift Question

swift 2.2 basic, if statement doesn't compile

Pardon me for beginner's question, Why this code got complained about

{ expected after if
, the braces are already there

var years = Int(edtYears.text!)
if years !=nil {
//do something
}else {
//...
}


Thanks

Answer

You need to add space between both side of condition like if years != nil { or you can also write without space but the both side if years!=nil {

var years = Int("")

if years != nil {
    //do something
}else {
        //...
}
Comments