2016-11-14 99 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

相关问题