使用 swift 将分数保持在 XCode

Keeping score in XCode using swift

所以我想在 XCode 项目中保留一个 Score。但我希望它像 0.01, 0.02... 直到到达 1.00 并从 1 继续像 1, 2, 3...

我当前的代码如下所示:

var Highscore = 0
var Score = 0

...

@IBAction func Action(sender: AnyObject) {

if (Score < 100) {

        Score++
        HighScoreLabel.text = "HighScore:\(Score)"

} else if (Score >= 100) {

        Score += 100
        HighScoreLabel.text = "HighScore:\(Score)"

我已经尝试创建一个除以 Score 的变量,我试图将其设为双倍(但我想要 1, 2.. 而不是 1.00, 2.00),但我不知道是什么去做。 如果可以请帮助我,并随时编辑。

func action() {
    if (score < 100) {
        score += 1
        let someScore = score < 1 ? String(format: "%.2f", score) : String(format: "%.f", round(score))
        println("HighScore:\(someScore)")
    } else if (score >= 100) {
        score += 100
        let someScore = score < 1 ? String(format: "%.2f", score) : String(format: "%.0f", round(score))
        println("HighScore:\(someScore)")
    }
}

这应该可以做到。

编辑:
使用了您的代码。