Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get list of files at path swift [duplicate]

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.

like image 993
Olexiy Pyvovarov Avatar asked Sep 27 '14 08:09

Olexiy Pyvovarov


1 Answers

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)
}
like image 78
Clafou Avatar answered Oct 10 '22 10:10

Clafou