I've been struggling for over an hour now trying to figure out what I'm supposed to do in order to write a Data object to a file in the caches folder. This is something I've done hundreds of times in Objective-C over ten years.
Here's how I got the reference to the caches folder:
let paths = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)
let cachesDirectory: URL = paths[0]
I then concatenated a filename to it:
let path = "\(cachesDirectory.absoluteString)/foo.json"
I then tried various ways to write the data including the Data.write function, the FileManager createFile function, and also by creating a FileHandle and writing to that. In each case the operation fails with an error that says "No such file or directory foo.json" or something to that effect.
What am I doing wrong?