2015-09-25 38 views
0

改變代碼爲2,從夫特1改變代碼爲2,錯誤:類型 'NSDirectoryEnumeration選項' 不符合從夫特1協議 'NilLiteralConvertible'

Error: Type 'NSDirectoryEnumeration Options' does not conform to Protocol 'NilLiteralConvertible' on line 6 below:

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 
     } 
    } 

回答

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

+0

感謝你爲這個。 –

+0

歡迎@cookiemonsta –

相關問題