// // AppDelegate.swift // import Cocoa import AVFoundation @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { @IBOutlet weak var window: NSWindow! func applicationDidFinishLaunching(aNotification: NSNotification) { let audioPath = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("test", ofType: "wav")!) let player : AVAudioPlayer player = try! AVAudioPlayer(contentsOfURL: audioPath, fileTypeHint: nil) player.prepareToPlay() player.play() } }
Note that I am using Xcode 7.2.1. At line 16, if you do not use try, you will get the error message, Call can throw, but it is not marked with `try’ and the error is not handled.
I am using try! to disable error propagation.