【问题标题】:Error with pathForResource: inDirectorypathForResource 出错:inDirectory
【发布时间】:2015-02-20 13:30:41
【问题描述】:

我创建了子文件夹“Sounds”并添加了文件“backstage.mp3”

这很好用:

var path = NSBundle.mainBundle().pathForResource("backstage", ofType: "mp3")!

但是当我尝试添加 inDirectory

var path = NSBundle.mainBundle().pathForResource("backstage", ofType: "mp3", inDirectory: "Sounds")!

它因致命错误而崩溃:

致命错误:在展开可选值时意外发现 nil

【问题讨论】:

    标签: swift


    【解决方案1】:

    问题来自您导入文件的方式。

    确保在弹出窗口中选择“如果需要,复制项目”和“创建文件夹引用”。

    否则该子文件夹实际上并不存在于应用程序包中。

    【讨论】:

      猜你喜欢
      • 2014-11-21
      • 1970-01-01
      • 1970-01-01
      • 2011-04-26
      • 2012-03-09
      • 1970-01-01
      • 1970-01-01
      • 2015-09-23
      • 2012-02-27
      相关资源
      最近更新 更多