//Declarations
var scoreIncrement:Int = 0
var team = ""
var userScore = Dictionary<String,Int>()
//Set Values
team = "USA"
userScore[team] = 0
//Store in NSUserDefaults
NSUserDefaults.standardUserDefaults().setObject(userScore, forKey: "userScore")
NSUserDefaults.standardUserDefaults().synchronize()
//Increment Score
scoreIncrement = 1
userScore[team]! += scoreIncrement
以上代碼給出關於代碼的最後一行「EXC_BAD_ACCESS(代碼= EXC_I386_GPFLT)」錯誤。然而,如果我評論出行:貯藏字典中引起NSUserDefaults的EXC_BAD_ACCESS
NSUserDefaults.standardUserDefaults().setObject(userScore, forKey: "userScore")
錯誤消失。任何想法爲什麼發生這種情況,我甚至沒有從NSUserDefaults中檢索字典。