自从我更新 Xcode 以来,我目前遇到了那段代码的错误
{!}Call can throw, but is not marked with 'try' and the error is not handled
let soundURL = NSBundle.mainBundle().URLForResource("jump", withExtension: "caf")
audioPlayer = AVAudioPlayer(contentsOfURL: soundURL!, fileTypeHint: nil)
audioPlayer.numberOfLoops = -1
audioPlayer.play()
最佳答案
该方法现在是可抛出的,所以您可以这样处理它:
do {
audioPlayer = try AVAudioPlayer(contentsOfURL: soundURL!, fileTypeHint: nil)
audioPlayer.numberOfLoops = -1
audioPlayer.play()
} catch {
}
关于xcode - Swift Error 未处理且未标记为 try,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33318113/