2016-11-14 98 views
-4
var audioPath = NSURL(fileURLWithPath: Bundle.main.path(forResource: "vellipomaakey", ofType: "mp3")!). 

fatal error: unexpectedly found nil while unwrapping an Optional value 致命錯誤:意外發現零而展開的可選值

+0

的[什麼是「致命的錯誤:零而展開的可選值意外地發現」?意味着]可能的複製(https://stackoverflow.com/questions/32170456/what-does-fatal-error-unexpectedly-發現-未繳而-去包裹-AN-可選-VALU) – xoudini

回答

0

您是力量展開您的選購,應考慮以下幾點:

if let res = Bundle.main.path(forResource: "vellipomaakey", ofType: "mp3") { 
    var audioPath = NSURL(fileURLWithPath:res) 
} 

這很可能會帶走你的運行時錯誤,但它將無法解決您的問題。這裏的問題是您正在嘗試加載的資源未找到,因此Bundle.main.path(forResource: "vellipomaakey, ofType: "mp3")正在返回nil

0

您是否在Copy Bundle Resources部分看到了它?如果不是,請按+符號來添加該mp3文件。 enter image description here

相關問題