ios - Swift Xcode 6 developer baseball counter -


this question has answer here:

at end of code i'm trying make when 3 strikes outs go one. i'm getting error @ bottom if statement. says expected declaration

// //  viewcontroller.swift //  helloworddemo // //  created developer on 6/8/14. //  copyright (c) 2014 aecapps. rights reserved. //  import uikit  class viewcontroller: uiviewcontroller {  override func viewdidload() {     super.viewdidload()     // additional setup after loading view, typically nib. }  override func didreceivememorywarning() {     super.didreceivememorywarning()     // dispose of resources can recreated. } @iboutlet var labeldispaly : uilabel = nil // dispaly strikes  var counter = 1  @ibaction func buttonpressed(sender : anyobject) {      labeldispaly.text = "strikes \(counter++)" } //button add strikes  @iboutlet var outsdispaly : uilabel = nil  var outscounter = 1 //outs dispaly  @ibaction func outsbuttonpressed(sender : anyobject) {      outsdispaly.text = "outs \(outscounter++)"  } //button add outs if counter = 3 {     outscounter ++    } } 

the problem if statement not inside function. ok when statement outside class, not in case. write function run statement. add class:

func updateouts(){     if counter == 3 {         outscounter++     } } 

also, inside if statements should use == instead of =. because == compare 2 values , = sets variable.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -