Skip to content

Instantly share code, notes, and snippets.

@Mazyod
Last active October 7, 2015 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mazyod/4fbe7284d29db2121484 to your computer and use it in GitHub Desktop.
Save Mazyod/4fbe7284d29db2121484 to your computer and use it in GitHub Desktop.
recursively get files with certain data type from NSBundle
extension NSBundle {
func recursivePathsForResources(type type: String) -> [NSURL] {
// Enumerators are recursive
let enumerator = NSFileManager.defaultManager().enumeratorAtPath(bundlePath)
var filePaths = [NSURL]()
while let filePath = enumerator?.nextObject() as? String {
if NSURL(fileURLWithPath: filePath).pathExtension == type {
filePaths.append(bundleURL.URLByAppendingPathComponent(filePath))
}
}
return filePaths
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment