[swift-users] FileManager.copyItem not throwing?

John Brownie john_brownie at sil.org
Fri Nov 10 19:31:31 CST 2017


I have code as follows:

let fileManager = FileManager.default
do {
     try fileManager.createDirectory(at: 
destination.deletingLastPathComponent(), withIntermediateDirectories: 
true, attributes: nil)
     try fileManager.copyItem(at: source, to: destination)
     handler(true, nil)
}
catch let theError as NSError {
     if theError.code == NSFileWriteNoPermissionError {
         ...
     }
     else {
         ...
     }
}
catch {
      handler(false, NSError(...))
}

Running on macOS 10.12.6, Xcode 8.3.2, I get to the copyItem call, which 
shows an error on the console:

2017-11-11 11:18:25.931446+1000 MyApp[32662:2408351] open on 
/path/to/file: Permission denied

But it doesn't go to either of my catch blocks, but goes to the 
following line, where the completion handler is to be run. What is going on?

John
-- 
John Brownie
SIL-PNG, Ukarumpa, Eastern Highlands, Papua New Guinea
Mussau-Emira language, New Ireland Province, Papua New Guinea


More information about the swift-users mailing list