|
I'm at the point where I've figured out how to save files on the phone similar to what Paul had shown us with UserDefaults, using the code below. I'm now trying to figure out how I can access this file from somewhere else; attached to an e-mail, saved to the iCloud Drive, or whatever. Basically, I want a copy of the file verses.json on my laptop. The closest thing I've found is this: https://www.hackingwithswift.com/quick-start/swiftui/how-to-export-files-using-fileexporter but it doesn't have all the information I need and the one before and after it don't seem to help either. Does Paul have any tutorials on doing this? Or are there any videos on working with files in general?
|
|
I have upgraded my code above to the following below and it all seems to work, but I'm no closer to figuring out how to export files.
|
|
While I haven't figured out how to export one of my saved files in my App from my phone, I did manage program a button to dump all my data into a string and then export it as a plain text CSV file into my iCloud Drive, using the information from these two urls: https://www.hackingwithswift.com/quick-start/swiftui/how-to-export-files-using-fileexporter https://betterprogramming.pub/importing-and-exporting-files-in-swiftui-719086ec712 I still have a long ways to go in understanding this stuff, so if someone could point me to some more basic tutorials, I would appreciate it. |
|
Hello, what is your use case for getting these files? Do you want the users of your app be able to access them also and possibly share them for debug purposes? For your own apps, you can actually inspect all the data via Xcode. Like this: Window -> Devices and Simulators -> select the device and app in the list -> click the small "gear" icon below -> Download container... This will download special package, you can right-click the file on your Mac and select "Show package contents". It will show you everything in your apps directory. Another option which I used recently is to make your app's "Documents folder" (usually the default one when you use |
|
Yes, I want users to be able to access the data, even though I am currently the only user. I want to make it possible to get a copy of the data without having to use Xcode. The reasons for accessing the files are 1. To have a backup copy of the data for backup and restore purposes, 2. To have a copy of the data for doing other things with it, for instance, I have several apps that I use that at the end of the year I want to be able to get a copy of the data for tax purposes. I want a permanent copy of it in my tax records and for use in preparing my taxes. I looked through your blog and that looks like a reasonable option. I'll have to play around with it. I don't want users, including myself, to have direct access to the data, because that could cause all kinds of issues. Instead I want them to access a copy of it. From reading your blog, it sounds like that is possible. Thanks. |
|
Nice! With the documents folder approach in files, you can use it as export destination while keeping your data either in a database or perhaps in the "Application Support" directory (the linked blog post shows how). I think this will be pretty solid solution. Another option might be to export to iCloud Drive folder which gives the benefit of automatic backup (it works basically the same as documents folder - just the target URL is different). And lastly option for the documents folder might be to use hidden files for stuff you don't want users to touch. iOS will hide any file that starts with dot, for example |
|
SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.
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.