从Swift中的Path获取Bundle引用

Alo*_*lok 8 filepath nsbundle ios swift

我想从swift中获取Path的NSBundle引用.

就像在Objective-c>中一样

NSBundle* languageBundle = [NSBundle bundleWithPath:path];
Run Code Online (Sandbox Code Playgroud)

我们如何在迅速实现同样的目标.

Avi*_*are 10

试试这个

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

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

斯威夫特4:

var pathForFile = Bundle.main.path(forResource: "Filename", ofType: "db")
Run Code Online (Sandbox Code Playgroud)


Dha*_*esh 3

这样你就可以快速做到这一点:

let languageBundle = NSBundle(path: path)
Run Code Online (Sandbox Code Playgroud)