I’m confused by this:
let destinationURL = destinationDIrectory.appendingPathExtension(sourceURL.lastPathComponent)
A path extension is the text after the dot. For example, in this:
let sourceURL = URL(fileURLWithPath: "/Users/quinn/test.txt")
the path extension is txt
. Given that, adding the last path component as a path extension is a type error. Consider this:
let destinationDirectory = URL(fileURLWithPath: "/Users/quinn/Test")
let destinationURL = destinationDirectory.appendingPathExtension(sourceURL.lastPathComponent)
print(destinationURL)
On current systems (macOS 12.4) this prints:
file:///Users/quinn/Test.test.txt/
which is syntactically correct but semantically nonsense.
My best guess is that you intended to call appendingPathComponent(_:)
, which yields:
file:///Users/quinn/Test/test.txt
which makes a lot more sense.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"