How to display a score count

I am trying to pull data from a database to display on profile for score count and basically trying to set the label's text in Xcode. What is the best way to do this since what I am doing is throwing errors. I am trying to see what I did wrong. Thanks

I did

let user = PFUser.current!
if let score = user["score"] as? Int {
scoreLabel.text = score
} else {
scoreLabel.text = user.score
}
Answered by chizy in 676529022

Resolved

Accepted Answer

Resolved

Great you found a solution.

A few comments on good practices on the forum:

  • describe precisely the erros you get and where you get it.

what I am doing is throwing errors

is of little use.

  • When you have a solution, explain what you changed.

That may be useful for others who will read your problem.

Most likely, in your case

scoreLabel.text = score

you try to give an Int value to a String property. That cannot work.

scoreLabel.text = String(score)

Now, both sides are String.

Have a good continuation.

Basically just did this to get what I needed.

let user = PFUser.current!
if let highScore = user["highScore"] as? Int {
highscoreLabel.text = String(highScore)
 }
How to display a score count
 
 
Q