Naro Naro - 2 months ago 7
iOS Question

I am trying to indent data when displaying using \t in swift but it isn't working

I am trying to print() out the two arrays but instead of displaying in a row with a \t(tab) in between each number.
it is displaying in a column and no \t.
Not sure what I am doing wrong.

for j in 0 ..< dicePossibleNum.count
{
print("\(dicePossibleNum[j])\t") //displays possible dice numbers
}


print("\n==================================================\n")

for i in 0 ..< diceResult.count
{
print("\(diceResult[i])\t") // displays dice results
}


Here is the result

2

3

4

5

6

7

8

9

10

11

12

==================================================

4

2

7

4

21

18

14

13

6

10

2

Thank you for any help,
I'm all new to programming.

Tim Tim
Answer

Swift 'print()' function appends a newline by default. Try

print("Hello", terminator:"")

This makes 'print()' add an empty string at the end of the line, instead of a newline. You could also try:

print("Hello", terminator:"\t")

...which would add a tab at the end of the line.