John Ramos John Ramos - 1 year ago 116
iOS Question

Convert text to .docx document file and open share dialog, Swift 2

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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download