Last active
October 7, 2015 22:33
-
-
Save Mazyod/4fbe7284d29db2121484 to your computer and use it in GitHub Desktop.
recursively get files with certain data type from NSBundle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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