我的代码如下:
let mvc = MainViewController()
let average = mvc.defaults.array(forKey: "grades") as! [Int]
let averagePoints = mvc.defaults.integer(forKey: "averagePoints")
gradePoints = averagePoints/average.count
在最后一行,我收到一个EXC_BAD_INSTRUCTION(代码= EXC_I386_INVOP,子代码= 0x0)错误。这意味着什么,为什么我会得到它?
感谢您的帮助!
答案 0 :(得分:0)
试试这个:
if let average = mvc.defaults.array(forKey: "grades") as? [Int],
let averagePoints = mvc.defaults.integer(forKey: "averagePoints") {
gradePoints = averagePoints/average.count
}
似乎grades
数组或/和averagePoints
是/是。