|
Paul mentioned we should think about a generic way to store files to disk using the home directory. Here's what I came up with. I intentionally let the methods throw so that I can deal with the errors "outside" of the call. Of course, wrapping it in do{} catch is possible and return optionals instead, for example. It was not specified for the task.
|
|
Here mine. Looking forward to see how Paul does it.
Call site
|
|
Great solution as well. You catch all the potential errors and throw fatal errors assuming that things "should be in place". I picked the approach that the methods are flexible for use cases when the file might or might not be there and the program does not fail. However, I see one clear difference I would like to ask your input. You do not write the data into the file but convert it to String. Is there any reason to a String being beneficial? I see it more as another "variable" to be aware of as you add UTF8 as a magic constant, for example. |
|
Can someone please explain how the above (either solution) can work if the message.txt already exists? i.e. it was saved using
as Paul did in his demonstration. |
|
Found it in case anyone was wondering the same..my code (it's for loading only):
And is being called like this:
|
|
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure and A/B test your entire paywall UI without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.