srajani
srajani

Reputation: 11

Swift and XCode 6 - Converting Integer to String

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
}

Upvotes: 1

Views: 17073

Answers (3)

Madhu Kiran
Madhu Kiran

Reputation: 67

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

Upvotes: -1

NashuaDataSolutions
NashuaDataSolutions

Reputation: 1

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

Upvotes: 0

Abdullah
Abdullah

Reputation: 7233

label.text = String(value)

Or

label.text = "\(value)"

Or

label.text = value.description

Upvotes: 17

Related Questions