0

I have a multiline array which populates a tableview.

I now also want to use the array for a UITextView to display the string as it's currently being displayed.

I have it displaying everything as I want except for one of the symbols in the array which does not display as it should.

I feel like all I need is the right string format?

textView.text = String(format:"%@", array)

The code above is how I have it ALMOST working but the "x" symbol from the array is being substituted with "\U00d7"

The "x" does not appear to be an actual letter, (thus the "\U00d7") not an iOS one anyway.

Before adding the format "%@", the "x" symbol was being displayed as an x.

I want it to be displayed as I have entered it into the array rather than having to always change the "x" symbol for an iOS "X" symbol.

4
  • how is your strings encoded? utf8? Commented Oct 2, 2019 at 8:14
  • Can you demonstrate what king of input you have and what kind of output you are expecting??? e.g //Input array let array = ["a","b","c"] //Output string should be like "abc" or "a,b,c" or "a-b-c" etc Commented Oct 2, 2019 at 8:18
  • The output is identical to the input, the array is just holding multiline strings. Commented Oct 2, 2019 at 12:03
  • Like input = """1, 2, 3 1x 0.1%""" output = """1, 2, 3 1x 0.1%""". They need to also be on their own line. Commented Oct 2, 2019 at 12:17

1 Answer 1

3

Using String(format:_:) is not a good idea in this case. %@ does not work with utf8 encoding.

Try textView.text = array.joined() instead.

Sign up to request clarification or add additional context in comments.

3 Comments

This method doesn't keep the lines separate. Each string has it's own line but with .joined() it's continuous. Good to know this way too as it has its own benefits.
@Superlative If you want newlines between each character, please use joined(separator:) instead.
Thanks, much better, .joined(separator: String) and I made a string that was two lines.👍

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.