Get resource URL from project specific path

我怕爱的太早我们不能终老 提交于 2019-12-03 05:53:14
Wain

You would use one of the bundle resourse URL methods

[[NSBundle mainBundle] URLForResource:@"acknowledge1"
                        withExtension:@"wav"
                         subdirectory:@"snd/archer"];

NSBundle.mainBundle().URLForResource("acknowledge1", withExtension:"wav" subdirectory:"snd/archer")

In latest Swift:

Bundle.main.url(forResource: "acknowledge1", withExtension:"wav")
Guig

As of Swift 3, the answer is:

Bundle.main.url(forResource: "acknowledge1", withExtension: "wav", subdirectory: "snd/archer")

In Swift 2.3 you'd have to use this unwrapping:

if let resourceUrl = NSBundle.mainBundle().URLForResource("acknowledge1", withExtension: "wav", subdirectory:"snd/archer") {
        if NSFileManager.defaultManager().fileExistsAtPath(resourceUrl.path!) {
            print("file found")
            //do stuff
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!