2015-07-29 14 views

risposta

3

In questo modo si può fare a Swift:

let languageBundle = NSBundle(path: path) 
+0

ma il suo ritorno nullo per me. – Alok

+0

qual è il tuo percorso? –

+0

voglio recuperare un file di stringa dal pacchetto per scopi di localizzazione. – Alok

7

Prova questa

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

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

Per Swift 3:

let bundleFromPath = Bundle(path: path) 

Per caricare un elenco di file dal bundle:

let docPath = Bundle.main.resourcePath! + "/" + bundleName + ".bundle" 
let fileManager = FileManager.default 
do { 
    let filesFromBundle = try fileManager.contentsOfDirectory(atPath: docPath) 
    print(filesFromBundle) 
} catch {} 
Problemi correlati