Skip to content

Instantly share code, notes, and snippets.

@m-etka
Created June 27, 2016 10:53
Show Gist options
  • Save m-etka/4e116305c721c89a1c5c319ee80fe7bc to your computer and use it in GitHub Desktop.
Save m-etka/4e116305c721c89a1c5c319ee80fe7bc to your computer and use it in GitHub Desktop.
Iterate file names in iOS documents directory.
// 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