Reputation: 1
let audioPath = Bundle.main.path(forResource: songs[indexPath.row], ofType: ".mp3", inDirectory: "Songs")!
Returns nil. songs[indexPath.row] returns the correct name, as it is exactly in the folder named "Songs". The songs folder is blue and shows up correctly in my build phases->copy bundle resources
Upvotes: 0
Views: 516
Reputation: 535
I replied in the comment above but I should go to this place to upload the image and recap my opinion again:
make sure you removed the dot .
: mp3
instead of .mp3
songs[indexPath.row]
value must not be optional, because it can cause a string like this: Optional(MyFileName)
, and the value must not contains the extension .mp3
, just filename only.
Look at the picture below, if you Bundle.main
equivalence is not a selected target in the list of File Inspector, the audioPath
may be nil
. So you have to check them for all of your mp3 files.
Upvotes: 2