我需要运行以下代码。

let illinois = College(name: "University od Illinois", location: "Urbana-Champaign", numberOfStudents: 35000, image: UIImage(named: "Default")!)

let missouri = College(name: "University of Missouri", location: "Columbia", numberOfStudents: 34658, image: UIImage(named: "MissuouriImage")!)

let iowa = College(name: "University of Iowa", location: "Iowa City", numberOfStudents: 31065, image: UIImage(named: "IowaImage")!)

colleges = [illinois, missouri, iowa]

在密苏里州,它表示exc_bad_指令(code=exc_i386_invop,subcode=0x0),下面是一个图像:
http://i.stack.imgur.com/euCg8.png

最佳答案

此代码导致崩溃:

UIImage(named: "MissuouriImage")!

检查图像是否存在(可能称为“密苏里州图像”),并考虑展开您的选项以确保它存在:
if let missouriImage = UIImage(named: "MissuouriImage") {
    let missouri = College(name: "University of Missouri", location: "Columbia", numberOfStudents: 34658, image: missouriImage)
}

关于swift - 如何调试“EXC_BAD_INSTRUCTION(code = EXC_I386_INVOP,subcode = 0x0)”Swift错误?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30057438/

10-10 19:57