ios – Textual content file cannot be created inside a folder

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 machine, however I nonetheless get this error. Please discover my code beneath:

let path = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!

let logPath = path.appendingPathComponent("Logs").appendingPathComponent("log.txt")

attempt! "Hey world".write(to: logPath, atomically: true, encoding: .utf8)

Nonetheless, if I change the logPath with path.appendingPathComponent("log.txt"), it should work, BUT it creates the file outdoors of the folder Logs as a substitute of inside.

How can I remedy this?

Related Articles


Please enter your comment!
Please enter your name here

Latest Articles