Search code examples
arraysswiftprintingreturnline

how to get array entry to print on new line each time (swift3)


When my array is being printed the entries are bing printed on the same line. I have tried \n command in a couple of ways but I have not gotten it to work. I just want to print 1 array entry on 1 line then move to the next line. pic of array printed out

var arrayOfInt = [Int]()


 let cars = arrayOfInt.map { "car \($0)" }
  label.text =  String(describing: cars)

Solution

  • Have you tried this ?

    label.text = arrayOfInt.map { "car \($0)" }.joined(separator:"\n")