Get Bundle reference from Path in Swift

Alok picture Alok · Jul 29, 2015 · Viewed 15.5k times · Source

I want to get NSBundle reference from Path in swift.

Like in Objective-c >

NSBundle* languageBundle = [NSBundle bundleWithPath:path];

How we can achieve same in swift .

Answer

Avijit Nagare picture Avijit Nagare · Jul 29, 2015

Try this

 var path = NSBundle.mainBundle()//path until your project name.app

 var pathForFile = NSBundle.mainBundle().pathForResource("Filename", ofType: "db")// path of your file in bundle

Swift 4:

var pathForFile = Bundle.main.path(forResource: "Filename", ofType: "db")