将代码从Swift 1更改为2,
错误:输入' NSDirectoryEnumeration选项'不符合协议' NilLiteralConvertible'在下面的第6行:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if let directoryURL = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as? NSURL {
let urls = try! NSFileManager.defaultManager().contentsOfDirectoryAtURL(directoryURL, includingPropertiesForKeys: nil, options: nil
}
}
答案 0 :(得分:1)
没有选项
let enumerator = manager.enumeratorAtURL(url, includingPropertiesForKeys: keys, options: [], errorHandler: nil)
只有一个选项
let enumerator = manager.enumeratorAtURL(url, includingPropertiesForKeys: keys, options: .SkipsHiddenFiles, errorHandler: nil)
多个选项
let options: NSDirectoryEnumerationOptions = [.SkipsHiddenFiles, .SkipsPackageDescendants]
let enumerator = manager.enumeratorAtURL(url, includingPropertiesForKeys: keys, options: options, errorHandler: nil)
资源(由@Marc回答): Issue with returning a Directory Enumerator from NSFileManager using enumeratorAtUrl in Swift