Swift 5.0
Swift 5:
Caveat: Assumes that your folder is actually in the bundle; (that you added the folder to the project via 'Add Folder Reference', not by the 'Add Groups' option).
bundle.main.path(forResource: "myfolder", ofType: nil)
Objective-C: (your example)
NSString *folder = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"myfolder"];
Other Swift ways:
As a URL (Apple's preferred method, the :URL?
is only included here to clarify that this does not produce a string):
let folderURL:URL? = Bundle.main.url(forResource: "myfolder", withExtension: nil)
Appending as a string:
let folder = Bundle.main.resourcePath?.appending("/myfolder")
// or
let y = Bundle.main.resourcePath?.appending("/").appending("myfolder")
The following literal translation fails, as appendingPathComponent is no longer available in the Swift String
type which is slightly different from NSString
:
let folder = Bundle.main.resourcePath?.appendingPathComponent("myfolder")