Created
June 27, 2016 10:53
-
-
Save m-etka/4e116305c721c89a1c5c319ee80fe7bc to your computer and use it in GitHub Desktop.
Iterate file names in iOS documents directory.
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
// Get documents directory | |
let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true) | |
let documentsDirectory = paths[0] | |
// Create enumerator | |
let fileManager = NSFileManager.defaultManager() | |
let enumerator:NSDirectoryEnumerator = fileManager.enumeratorAtPath(documentsDirectory as String)! | |
// Iterate files | |
while let element = enumerator.nextObject() as? String { | |
print(element) | |
if element.hasSuffix("jpg") { // Check extension | |
print("jpg file") | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment