How to write text file and save it using just -ipad swift playground 4- ?

How to write a text file in swift playground 4 ipad version ?

And how can i see it in Files app ?

swift 5, is it possible to do it with just swift playground 4 of iPad version?

Yes its possible! Its kinda complicated though. To access the external Files storage area the user has to be shown a sheet to grant access to a folder. But once granted a security scoped bookmark can be saved locally (in UserDefaults or a local file) so that folder can be accessed again without bugging the user.

It took me awhile to work the whole process out and I tried to wrap it up in easy to use load and save Buttons. It had to be some kind of view to have a place to show the sheet. Anyways my implementation is working well but it’s designed to read and write to only one specific file in the selected folder with Codable objects. Thats’s something I plan to refactor but looking over the code it can give you the idea, or at least the keywords to lookup and see what the necessary parts are.

See it here https://github.com/trochoid/EZIO

There’s a ButtonSave and ButtonLoad view with the relevant code but they also call static functions in the EZIO class. Documentation is basically missing and, um, the error handling is atrocious embarrassed. That’s the other part I plan to refactor, please look passed it to how it otherwise works and I can answer questions.

How to write text file and save it using just -ipad swift playground 4- ?
 
 
Q