I am attempting to create a log.txt
file inside a folder of a tool, however I get this error:
NSCocoaErrorDomain Code=512 “The file “log.txt” couldn’t be saved in
the folder “Logs”.
The folder Logs
already exists on the system, however I nonetheless get this error. Please discover my code under:
let path = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let logPath = path.appendingPathComponent("Logs").appendingPathComponent("log.txt")
strive! "Hiya world".write(to: logPath, atomically: true, encoding: .utf8)
Nonetheless, if I exchange the logPath
with path.appendingPathComponent("log.txt")
, it would work, BUT it creates the file exterior of the folder Logs
as an alternative of inside.
How can I resolve this?