0

I need to be able to reference specific files within a directory inside of my xCode project. So far I have this code:

let files = NSBundle.mainBundle().pathForResource("sampleFile", ofType: "csv")
var contents = String(contentsOfFile: path!, encoding: NSUTF8StringEncoding, error: nil)!

Which works to open a single file, but I would like to be able to open a file that is stored inside one or two directories within the main bundle.

Does anybody know how to do this?

Matt Spoon
  • 2,760
  • 5
  • 25
  • 41

1 Answers1

0

There is a method of NSBundle to specify the directory for a single file

  let file = NSBundle.mainBundle().pathForResource("sampleFile", ofType: "png", inDirectory:"Images")

or for multiple files of the same type

  let files = NSBundle.mainBundle().pathForResourcesOfType("png", inDirectory:"Images")
vadian
  • 274,689
  • 30
  • 353
  • 361