gpt4 book ai didi

swift - 默认值太复杂,无法使用基本的 '+' 运算符进行编译

转载 作者:行者123 更新时间:2023-11-30 10:06:24 25 4
gpt4 key购买 nike

func updateTotalScore() -> Int {
var totalScoreDefault = NSUserDefaults.standardUserDefaults()

var highScoreAB1 = defaults.integerForKey("highScoreAB1")

var highScoreAB2 = defaults.integerForKey("highScoreAB2")

var highScoreAB3 = defaults.integerForKey("highScoreAB3")

var highScoreAB4 = defaults.integerForKey("highScoreAB4")
var highScoreAB5 = defaults.integerForKey("HighScoreAB5")
var highScoreAB6 = defaults.integerForKey("highScoreAB6")
var highScoreAB7 = defaults.integerForKey("highScoreAB7")
totalScoreDefault =
(defaults.integerForKey("highScoreAB1") + defaults.integerForKey("highScoreAB2")) + (defaults.integerForKey("highScoreAB3") + defaults.integerForKey("highScoreAB4")) + (defaults.integerForKey("highScoreAB5") + defaults.integerForKey("highScoreAB6")) + defaults.integerForKey("highScoreAB7") }

添加多个键以获得默认总分会引发以下错误。我尝试将它们分成两两,但没有成功。先感谢您。这是昨天帖子的延续。

最佳答案

作为 Logan 答案的补充,因为您说您遇到“复杂表达式”编译器错误的问题。这应该编译:

func updateTotalScore() -> Int {

let defaults = NSUserDefaults.standardUserDefaults()

let totalScoretDefault =
defaults.integerForKey("highScoreAB1") +
defaults.integerForKey("highScoreAB2") +
defaults.integerForKey("highScoreAB3") +
defaults.integerForKey("highScoreAB4") +
defaults.integerForKey("highScoreAB5") +
defaults.integerForKey("highScoreAB6") +
defaults.integerForKey("highScoreAB7")

return totalScoretDefault

}

关于swift - 默认值太复杂,无法使用基本的 '+' 运算符进行编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35729564/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com