ios - Swift: Expected declaration of var even though it has been declared -


i'm new swift , trying program simple counter app. i'd post messages on screen depending on value of variable. can't access though (i think) it's not instance variable. did wrong?

var rowvalue: int = 0     @iboutlet weak var motivationlabel: uilabel! @iboutlet weak var rowcount: uilabel!  override func viewdidload() {     super.viewdidload() }   @ibaction func subtractrowbutton(sender: anyobject) {     if rowvalue > 0 {         rowvalue = rowvalue - 1     } else {         rowvalue = 0     }      rowcount.text = "\(rowvalue)"  }  @ibaction func addrowbutton(sender: anyobject) {     rowvalue = rowvalue + 1     rowcount.text = "\(rowvalue)"      if rowvalue < 10 {         println("not bad")     } else if rowvalue > 9 && rowvalue < 20 {         println("awesome")     } }     @ibaction func resetbutton(sender: anyobject) {     rowvalue = 0     rowcount.text = "\(rowvalue)" } 

error not var. because of have written code directly inside class not inside function. causing issue.

replace conditional block like

 func dosomething(){    if(rowvalue < 10)    {     println("not bad")    }    else if(rowvalue > 9 && rowvalue < 20)    {     println("awesome")    }  } 

and call function dosomething() wherever want.


Comments