DcCoO DcCoO - 3 years ago 271
iOS Question

Can't find URL from files using Bundle main url

I'm trying to play some small .wav files using AudioToolBox library, but I just can't get the url for the files that I dragged into the project folder (the folder which contains the classes, etc.)

if let soundUrl = Bundle.main.url(forResource: name, withExtension: "wav") {
//make use of AudioServicesCreateSystemSoundID...
else {
print("sound wasn't found")

I tried all combinations of possible drags to xcode (Copy itens if needed, Create groups, Create folder references) and very frequently I Clean the project, but still I always get "sound wasn't found". I truly don't know what information to give, but my approach was working until some days ago, then it suddenly stopped...

PS: Not sure if it's a useful information but I printed the list of files at Bundle.main.bundlePath and I didn't find any of the files I wanted, although they all appear in the list of files in the left (that contains codes, xcassets, Main.storyboard, etc.)

Answer Source
  • Click at one of your wav files
  • At the right side, there will be a list of options
  • The last option of this list is a tab called Target Membership
  • Check if this wav file you chose marks your current project as target

hope that helps :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download