Why can I not put an if statement anywhere in my code? I am using swift

155 Views Asked by At

I just started writing a new app in Xcode beta 6 and I need to write an if statement for my code to work but I keep getting the error Expected declaration no matter where I put the if statement. my code is

let randomNumberColorPicker = arc4random_uniform(4) + 1



 if randomNumberColorPicker == 1 {
}

override func viewDidLoad() {
    super.viewDidLoad()
       }

What can I do to actually make this work?

1

There are 1 best solutions below

0
weePee On

From what I can see, your code is not in a function. Move your code into viewDidLoad:

override func viewDidLoad() {
    super.viewDidLoad()
    let randomNumberColorPicker = arc4random_uniform(4) + 1
     if randomNumberColorPicker == 1 {
       println("true")
    }else{
        println("falseMove your code int viewDidLoad")
    }
 }