1

I have an Xcode project with a label and a UIAction button. Upon tapping the button, I want the value displayed in the label to increase by 1. The problem is that I can't display the variable "value" in the label, because it's an integer, and the label takes a String data type. Here is the code I have so far:

var value = 0 

@IBOutlet var label: UILabel!

@IBAction func button(sender: AnyObject) {
    value = value + 1
    label.text = value
}
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571
srajani
  • 11
  • 1
  • 1
  • 2

3 Answers3

17
label.text = String(value)

Or

label.text = "\(value)"

Or

label.text = value.description
Abdullah
  • 7,143
  • 6
  • 25
  • 41
0

Of course I would save some typing and express it this way:

value++ 
label.text = value.description

In the end it is the same thing as:

value = value + 1
label.text = value.description
OhBeWise
  • 5,350
  • 3
  • 32
  • 60
-1

you can convert value before saving core data directly just like that

//core data 
userid value = string

we need to store Int value we have to convert the value explicitly like that. I tried that and it works fine core data contain task entity having user_id attribute

 tasksEntity.user_id = string

that should work