Get list of files at path swift

16,994

I think this may be possible by implementing an extension to NSFileManager that implements the SequenceType protocol. But you could easily convert your code to using a while loop:

let filemanager:FileManager = FileManager()
let files = filemanager.enumerator(atPath: NSHomeDirectory())
while let file = files?.nextObject() {
    print(file)
}
Share:
16,994
Olexiy  Pyvovarov
Author by

Olexiy Pyvovarov

Updated on June 18, 2022

Comments

  • Olexiy  Pyvovarov
    Olexiy Pyvovarov almost 2 years

    Just trying to make a for..in loop for files in the local app folder

    let filemanager:NSFileManager = NSFileManager()
    let files = filemanager.enumeratorAtPath(NSHomeDirectory())
    for filename in files!
    {
        println(filename)
    }
    

    But it says Type 'NSDirectoryEnumerator' doesn't conform to protocol SequenceType.