gpt4 book ai didi

xcode - Swift Error 未处理且未标记为 try

转载 作者:行者123 更新时间:2023-11-28 11:13:41 28 4
gpt4 key购买 nike

自从我更新 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com