Best way to load existing, formatted text into UITextView?

Hi,


I am new to programming.


I am currently working on a app that provides popovers with a UITextView when the user touches a certain part of an image. The popover's purpose is to provide a textual description of the area of the image where the user touched. The text is loaded from an array of dictionaries and it is different for each touch location.


The problem is that my text has formatting. Paragraphs, lists, headers in bold, etc. At the moment, my text is in a MS Word file, formatted, and it is around 15k words long.


My original plan was to copy the text into JSON, then parse the JSON into an array and access the text as needed. However, the formatting is lost in JSON. At least, as far as I know, there is no way or tool that can convert the text and keep the formatting. So I will have to edit every string (around 300 of them, some fairly long, with complicated formatting) manually, with escape characters, so that new lines and TABs will show properly in the UITextView. This will take me days to acomplish. What is worse, it will be really hard to maintain/update the JSON simply becaues the result is hard to read.


I am wondering if there is a better way to load this text. Is there a tool, that understands formatted text from a word processor, and then it creates a String that will display properly?


Thanks for any help!

TextView isn't your friend if formatting is your goal. Use a webview, instead. See the docs in the dev center for details.

The easiest way to do this is to convert your Word document to RTF. You can do this by copying and pasting the contents into TextEdit, and saving the result as an RTF file (not an RTFD). Then, you can read in the file into an NSAttributedString (there's init(URL:options:documentAttributes:) for this), which you can set as the value for the attributedText property on a UITextView.

Thank you for the answer!

Best way to load existing, formatted text into UITextView?
 
 
Q