The trick is to save the file locally as a .txt file and then open it using the UIDocumentInteractionController . Here is a complete code example:
import UIKit class ViewController: UIViewController, UIDocumentInteractionControllerDelegate { var interactionController: UIDocumentInteractionController? func openInPages(body: String, title: String) throws {
Call openInPages from anywhere in your code (for example, when the user clicks an Export button element):
openInPages("This will be the body of the new document", title: "SomeTitle")

source share