I built a basic tree data structure for my Swift-based iOS app, and I wanted to be able to print it out to the console for debugging purposes. So I wrote a function that would traverse through the tree (preorder) and print off the value at each node on it's own line with a number of tabs inserted before it based on the node's depth in the tree. By calling the function somewhere in the code, in the debugging console it would print like this:
root
node1
node1_1
node1_2
node2
node2_1
node2_1_1
node2_2
node3
node3_1
etc. This was good, and it allowed me to just call printInfo() in important places in the code, but I quickly realized that I needed to be able to print a String value on the spot like when I was paused at breakpoints. So I created a computed property infoString that would build a String from the tree with all the newlines (\n) and tabs (\t) thinking that I could just print it out in the debug console when I was at a breakpoint.
I tried it out with the command po infoString, but what it prints out to the console is this: "root\n\tnode1\n\t\tnode1_1\n\t\tnode1_2\n\tnode2\n\t\tnode2_1\n\t\t\tnode2_1_1\n\t\tnode2_2\n\tnode3\n\t\tnode3_1", which is technically correct, since that is what the String is, but I wanted to actually see the newlines and tabs.
So how do I print my String so that I see the newlines and tabs?