John Ramos John Ramos - 5 months ago 54
Swift Question

Create .docx file Swift and open share dialog

I have some text the user enters in my Swift 2 app. I need to convert it locally to a .docx file (either by modifying the text of an existing document or creating a new one) and then open up a

share dialog so the user can open this document up in Pages, Word, and Google Docs.

I am clear on how to open up a UIDocumentInteractionController, but right now I can only let the user share a .txt file; I need to let the user share a .docx file.


I figured this one out for you.

Take this answer user Casey made, and just change this line:

let fileName = "\(title).txt"

to this

let fileName = "\(title).docx"

and Swift will figure out that you want to export your text as a document, and do it automatically.