Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Bundle reference from Path in Swift

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 .

like image 377
Alok Avatar asked Jul 29 '15 09:07

Alok


2 Answers

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")
like image 187
Avijit Nagare Avatar answered Sep 25 '22 11:09

Avijit Nagare


This way you can do that in swift:

let languageBundle = NSBundle(path: path)
like image 44
Dharmesh Kheni Avatar answered Sep 24 '22 11:09

Dharmesh Kheni