var label = UILabel(frame: CGRectMake(0, 20, 200, 20)) label.textAlignment = NSTextAlignment.Center label.backgroundColor = UIColor.orangeColor() label.text = "lable" self.view.addSubview(label) let btn = UIButton(frame : CGRectMake(x, y , widthButton, heigthButton)) btn.setTitle((dicts["title"]), forState: .Normal) btn.backgroundColor = UIColor.blueColor() btn.addTarget(self, action: "press:" , forControlEvents: UIControlEvents.TouchUpInside) btn.tag = tag self.view.addSubview(btn) func press (sender: AnyObject) { if flag == true { sender.setTitle("player1", forState: .Normal) flag = false } else { sender.setTitle("player2", forState: .Normal) flag = true } } How to implement function that changed lable but not button? If you write lable.text then it is not available in the function, the declaration in the viewDidLoad method, where did I go wrong?