Reputation: 57
So in Obj-c this would be done differently, but I was wondering if anyone had any idea how to do this in swift? I feel embarrased having to ask this, but simply cannot find any documentation on it, how do I convert a float to string?
override func viewDidLoad() {
super.viewDidLoad()
var userScore = receivePlayerCard?.playerScore
var convertUserScoreToString: Float
scoreNameLabel.text = convertUserScoreToString //need to convert it to a string here
scoreNameLabel.textColor = UIColor.whiteColor()
// Do any additional setup after loading the view.
}
Upvotes: 2
Views: 7631
Reputation: 2843
We can use format strings with Swift's String
type, thanks to Obj-C bridging!
So for example:
override func viewDidLoad() {
super.viewDidLoad()
let userScore: Double = receivePlayerCard?.playerScore
scoreNameLabel.text = String(format: "%.2f", userScore)
// Do any additional setup after loading the view.
}
Upvotes: 2
Reputation: 64674
You'd do it like this:
scoreNameLabel.text = "\(convertUserScoreToString)"
Upvotes: 7