【发布时间】:2015-09-28 22:47:01
【问题描述】:
我尝试使用 Swift 2.0 播放声音 如果我写 'try' 没有 '!'我有错误 “不处理从这里抛出的错误” 而且 AVAudioPlayer 不是可选的,为什么 Xcode 请求“尝试!” 如果我写“试试!”我的应用程序崩溃 “在展开可选值时意外发现 nil”
class TouchViewController: UIViewController {
var soundPath:NSURL?
...................
//Play Bipsound
do { soundPath = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("Bipsound", ofType: "wav")!)
var sound = try! AVAudioPlayer(contentsOfURL: soundPath!, fileTypeHint: nil)
sound.prepareToPlay()
sound.play() }
【问题讨论】:
标签: ios swift avfoundation