簡體   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