func playCorrectSound() {
let soundURL: NSURL = NSBundle.mainBundle().URLForResource("correct", withExtension: "m4a")!
correctSound = try! AVAudioPlayer(contentsOfURL: soundURL)
correctSound.play()
}
func textFieldShouldReturn(textField: UITextField) -> Bool {
if correctIncorrectField.text == answerField.text && correctIncorrectField.text != "" && answerField.text != "" {
pointsNum = pointsNum + 10
points.text = "\(pointsNum)"
textField.text = ""
textField.hidden = true
correctIncorrect.hidden = false
correctIncorrect.textColor = UIColor.greenColor()
correctIncorrect.text = "Correct!"
pauseAndDoStuff()
playCorrectSound()
}
if correctIncorrectField.text != answerField.text && correctIncorrectField.text != "" && answerField.text != "" {
pointsNum = pointsNum - 5
points.text = "\(pointsNum)"
textField.text = ""
textField.hidden = true
correctIncorrect.hidden = false
correctIncorrect.textColor = UIColor.redColor()
correctIncorrect.text = "Incorrect!"
pauseAndDoStuff()
}
textField.resignFirstResponder()
return true
}
由于某种原因,它崩溃了
let soundURL: NSURL = NSBundle.mainBundle().URLForResource("correct", withExtension: "m4a")!
行和它唯一的说法:
致命错误:在解包可选值时意外发现nil。