iOS 15 - iOS 26.x, SwiftUI, Xcode 26.1.1 (rewritten without links)
I’m attempting to add the capability to export a file from CoreData.
Since ShareLink requires iOS16+, I found an article showing how to create a UIKit wrapper for 'UIActivityViewController' This does work, but I end up with multiple files instead of one. How do I merge this into one file?
Note: I don’t think I want to write to the app’s document directory – rather I’d like to allow the user to export to iCloud. Eventually, I’d like to share a list of dates with descriptions and if someone puts a sensitive date in there – I don’t want it to be left in a directory. I would include a warning that the file that they export needs to be handled with care if there are any sensitive dates. Some might consider birthdays as private information, right?
I'd also like to be able to name the file - so far when the share sheet comes up, I select "Save to Files" and it uses a default name of text.txt
My next step is to be able to import a CSV file (roundtrip) - could you point me to resources for how to do that?
No, you don't need to write the data as a file to your the app’s document directory.
With UIActivityViewController, you can share a piece of text, as shown in the following code example
let text = "This is a piece of text."
let activityViewController = UIActivityViewController(activityItems: [text], applicationActivities: nil)
With that, when activityViewController is presented, it shows the system-provided share UI that contains a Save to Files button, which allows you to save the text as a file to iCloud Drive. Tapping the button shows a UI that has a Save as field for you to input the file name for the taget file.
To import a file, consider using SwiftUI fileImporter.
Best,
——
Ziqiao Chen
Worldwide Developer Relations.