0

I have the following code working on playground, and I get the array at imageURLs.

let imagePath = str
let url = NSURL(fileURLWithPath: imagePath)
let fileManager = FileManager.default

let properties = [URLResourceKey.localizedNameKey, URLResourceKey.creationDateKey, URLResourceKey.localizedTypeDescriptionKey]
let imageURLs = try fileManager.contentsOfDirectory(at: url as URL, includingPropertiesForKeys: properties, options:FileManager.DirectoryEnumerationOptions.skipsHiddenFiles)

Then I add "do" "catch" to handle the errors on the project but it stops working.

let imagePath = Gal.urlDirectorio
let url = NSURL(fileURLWithPath: imagePath)
let fileManager = FileManager.default
let properties = [URLResourceKey.localizedNameKey, URLResourceKey.creationDateKey, URLResourceKey.localizedTypeDescriptionKey]


do { imageURLs = try fileManager.contentsOfDirectory(at: url as URL, includingPropertiesForKeys: properties, options:FileManager.DirectoryEnumerationOptions.skipsHiddenFiles)
  } catch {
       }

I follow the debugging process and everthing works until the "do" line. I have no error but it doesn't add the urls to the array.

JoseIgnacio
  • 49
  • 1
  • 9
  • 1
    How do you know that you get no error? You don't handle it. – vadian Mar 18 '17 at 08:26
  • @vadian is right, you should use `catch` to *catch* the exception and create an error with it yourself. Otherwise, your `do`/`catch` is just taking the `try` exception and ignoring it. – VitorMM Mar 30 '17 at 12:04
  • That should give you some light: http://stackoverflow.com/a/36454808/4370893 – VitorMM Mar 30 '17 at 12:07

0 Answers0