Search code examples
swiftcarriage-return

How to join an array of strings?


I am having problems attempting to return elements of a String array line by line within a textView. I have indeed used the special carriage return character in my code sequence to return elements of the array on separate lines. However, I have not been able to succeed thus far. Here is a code snippet of what I typed:

txtViewQuestionStatus.text = "\(numCorrect) correct Answers, However these are the questions answered INCORRECTLY: \(model.incorrectItems())\n" //Have text view present number of correct answers and list incorrect Questions line by line.

What could I be doing wrong in my source code? Thanks!


Solution

  • What is model.incorrectItems() returning? Can you post that part of your code? If it returns an array of strings you can join them like so:

    "... INCORRECTLY: \(model.incorrectItems().joinWithSeparator("\n"))\n"