Reputation: 6608
I currently run into a error with that bit of code since i updated 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()
Upvotes: 0
Views: 129
Reputation: 38162
With Swift 2, you should be handling exceptions. Below code should fix your problem:
do {
audioPlayer = try AVAudioPlayer(contentsOfURL: soundURL!, fileTypeHint: nil)
} catch (_) {
}
Upvotes: 1
Reputation: 27620
The method is now throwable so you have handle it this way:
do {
audioPlayer = try AVAudioPlayer(contentsOfURL: soundURL!, fileTypeHint: nil)
audioPlayer.numberOfLoops = -1
audioPlayer.play()
} catch {
}
Upvotes: 2