-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Learning Swift Second Edition
By :

It is very useful to write output to a log so that you can trace the behavior of code. As a codebase grows in complexity, it gets hard to follow the order in which things happen and exactly what the data looks like as it flows through the code. Playgrounds help a lot with this but it is not always enough.
In Swift, this process is called printing to the console. To do this, you use something called print
. It is used by writing print
followed by text surrounded by parentheses. For example, to print Hello World!
to the console, the code would look like this:
print("Hello World!")
If you put that code in a playground, you would see Hello World!
written in the results pane. However, this is not truly the console. To view the console, you can go to View | Debug Area | Show Debug Area. A new view will appear at the bottom of the window and it will contain all text the code has printed to the console:
Not only can you print static text to the console, you can also...
Change the font size
Change margin width
Change background colour