Bundle.main.path(forResource:ofType:inDirectory:) returns nil

后端 未结 10 2433
遥遥无期
遥遥无期 2020-12-07 13:08

Try not to laugh or cry -- I\'m just getting back into coding after 20 years out...

I\'ve spent more than 4 hours looking at references and trying code snippets to g

10条回答
  •  隐瞒了意图╮
    2020-12-07 13:42

    It's crazy how much time such a simple problem can cost.

    Some answers here helped me but I always tried:

    Bundle.main.url(forResource: selectedTitle, withExtension: "mp3")
    

    For some reason that doesn't work, but getting the path and translating it to a URL afterwards works:

    let path = Bundle.main.path(forResource: selectedTitle, ofType: "mp3")
    let url = URL(fileURLWithPath: path!)
    

提交回复
热议问题