3 ms·
let fileContents = try? String(contentsOfFile: "file.txt") That works perfectly fine. In the context of an iOS or MacOS app, that of course won't work, becaus
by RandallBrown 7y ago
let fileContents = try? String(contentsOfFile: "file.txt")
That works perfectly fine.
In the context of an iOS or MacOS app, that of course won't work, because apps only have access to certain directories. That is why you typically use the FileManager object to get the path to the directory you'll need.
- dmitriid 7y agoSearching Google for "read file swift" at best returns the StackOverflow answer in my screenshot. I would never in my life figure out that - reading from and writing to a file is not the job of file-related modules, but of a string - that it would just work like this wothout getting a proper handle to the file (what I assumed what the whole FileManager bruhaha was about)