How to display Int for display / SWIFT label

I'm not sure how to display int on the screen?

here is what i tried:

@IBOutlet weak var Button: UIButton! @IBOutlet weak var someLabel: UILabel! var someVar = 0 @IBAction func buttonPressed(sender: AnyObject) { someVar = someVar + 1 someLabel.text = (String)someVar } 

I linked the button and label to the view controller.

Thanks, sorry for the noob question.

+5
source share
4 answers

This is not a valid type in Swift.

 (String)someVar 

If String is a valid Int subtype, you can reset it using the "as" operator, but that is not the case.

In this case, you want to initialize a new line passing Int as an argument.

 someLabel.text = String(someVar) 
+25
source

Try using the following,

 someLabel.text = "\(someVar)" 
+4
source

you can do something like this:

 someLabel.text = NSString(format:"%d", someVar) 
+3
source

try it

 someLabel.text = "\(someVar)" 

Yes,

 someLabel.text = String(someVar) 

Go through this document https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/GuidedTour.html

+2
source

Source: https://habr.com/ru/post/1202934/


All Articles