Learn Swift - Chapter 1: print

If you wanted to display the words Yo, World! on a piece of paper, what is one way you might do that? One way might be to print those words to a piece of paper with a printer or copier.

What if you wanted to print those words on an LCD or other type of screen? In HTML you could do it like this:

<p>Yo, World!</p>

In Swift you would do it like this:

print("Yo, World!")

print is a keyword - which is a word that has a special meaning in Swift. This keyword means, Print, on the screen, the following message. Did you notice that print is typed all in lowercase? Swift is case sensitive, which is a way of saying that  to Swift, the programming language, Print is not the same thing as print. If you were to type this:

Print("Yo, World!")

you would get an error and it wouldn't work.

The parentheses, (), that encapsulate the quote, "Yo, World!", are a special requirement of Swift. You will get used to seeing them, as you will be typing them many times. If you haven't yet committed to muscle memory location of the 9 and 0 keys on your keyboard, you soon will.

In Swift, the text is between quotation marks like this "Yo, World!", and is called a string. It is a string of characters inside quotes. Another term for this, outside the world of programming, is a quote.

Notice how the opening quotation mark is immediately after the opening parenthesis. There are no spaces between the two. The same goes for the closing quotation mark and closing parenthesis. No spaces there either.

Swift, just like javascript, ignores spaces. You could write the same thing this way,

print( "Yo, World!")

or this way.

print("Yo, World!" )

But not this way.

print("Yo, World!")

See how the spaces in the last example are after the opening quotation mark? That would render the spaces in the printed message which would make it different than the other examples.