繁体   English   中英

当目录和文件名正确时,Bundle.main.path(forResource:ofType:inDirectory :)返回nil

[英]Bundle.main.path(forResource:ofType:inDirectory:) returns nil when directory and filename are correct

let audioPath = Bundle.main.path(forResource: songs[indexPath.row], ofType: ".mp3", inDirectory: "Songs")!

返回nil。 songs [indexPath.row]返回正确的名称,因为它恰好位于名为“ Songs”的文件夹中。 歌曲文件夹为蓝色,并在我的构建阶段->复制捆绑资源中正确显示

我在上面的评论中回答了,但我应该去这个地方上传图片并再次回顾一下我的观点:

  • 确保删除了点. mp3而不是.mp3

  • songs[indexPath.row] 不能是可选的,因为它可能导致这样的字符串: Optional(MyFileName) ,并且该值不能包含扩展名.mp3 ,而只能包含文件名。

  • 看下面的图片,如果Bundle.main等效项不是File Inspector列表中的选定目标,则audioPath可能为nil 因此,您必须检查它们的所有mp3文件。

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM