Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with returning a Directory Enumerator from NSFileManager using enumeratorAtUrl in Swift

Tags:

swift

I am attempting to return a NSDirectoryEnumerator object from the NSFileManager method enumeratorAtUrl. This results in a compiler error: Cannot convert the expressions type 'NSDirectoryEnumerator!' to type 'NSDirectoryEnumeratorOptions'

let url:NSURL = NSURL(fileURLWithPath: "/")
var keys:Array<AnyObject> = [NSURLNameKey, NSURLIsDirectoryKey]
var manager:NSFileManager = NSFileManager.defaultManager()
let enumerator:NSDirectoryEnumerator = manager.enumeratorAtURL(url,includingPropertiesForKeys: keys, options: 0, errorHandler: nil)

This works in Obj-C but not Swift.. Has anyone else encountered this issue?

like image 885
Daniel Rushton Avatar asked Jun 10 '14 23:06

Daniel Rushton


1 Answers

Try this:

let enumerator:NSDirectoryEnumerator = manager.enumeratorAtURL(url, includingPropertiesForKeys: keys, options: NSDirectoryEnumerationOptions(), errorHandler: nil)

Or in short, pass in NSDirectoryEnumerationOptions() instead of "0".

"0" is not really a member of the enumeration it is looking for.

like image 55
Kendall Helmstetter Gelner Avatar answered Oct 31 '22 11:10

Kendall Helmstetter Gelner