// // 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() } }
私はXcode 7.2.1を使っていることに留意して下さい。第16行であなたがもしtryを使わなければ、あなたはエラー・メッセージCall can throw, but it is not marked with `try’ and the error is not handled.を受け取るでしょう。
私はエラー伝搬を止めるために、try!を使っています。