I have an issue creating a subfolder in the user's documents folder on an iPhone device and simulator. Have tried both on iOS 12 and iOS 13. Have tried different subfolder names.
let directoryURLs = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
let documentsFolderUrl = directoryURLs.first ?? URL(fileURLWithPath: NSTemporaryDirectory())
let pathUrl = documentsFolderUrl.appendingPathComponent("offline")
// have also tried with .appendingPathComponent("offline", isDirectory: true)
if FileManager.default.fileExists(atPath: pathUrl.absoluteURL.path) == false {
do {
try FileManager.default.createDirectory(at: pathUrl, withIntermediateDirectories: true, attributes: nil)
// have also tried .createDirectory(atPath: pathURL.absoluteURL.path)
} catch(_) {
print("OfflineManager: Cannot create download contents folder at path: \(pathUrl.absoluteURL.path)")
}
}
The result of this operation is:
-rw------- 1 username access_bpf 31K Apr 23 10:30 offline
and so this a file and thus I cannot create a subfolder and write files into it.
What am I doing wrong?