Chapter 3.  Say Hello

For historic reasons, the first program we usually make when learning a new programming language is a program that simply outputs the text Hello World to the console. Printing to the console is reasonably simple and is, therefore, often a good starting point to ensure that everything is set up correctly. To honor traditions, we will do the same with our very first program written in the Swift programming language:

print("Hello World")

Exciting! To achieve this, the chapter will cover the following topics:

  • Introducing a console application
  • Setting up our first Xcode playground and taking a look at the most important parts of a playground
  • Writing our first Hello World program using Swift and a playground
  • A quick look at how Xcode playground communicates errors and how we can use autocompletion to write code faster and more safely

What is a console application?

You might be wondering what a console is. Before diving into writing the code, let's try to understand the difference between a console interface and a Graphical User Interface (GUI). We say that a console interface is an interface based on text. This means that we are able to interact with the interface using only text.

An application that uses a console interface can also be considered a console application. To understand what a console interface is like in practice, you can have a look at the interface of the Terminal application, which ships together with macOS:

What is a console application?

The Terminal application is a powerful application to control the underlying operating system. Everything is controlled by text in the sense that you write commands to instruct the operating system to do what you want. The output of your commands will be communicated back to you in text as well.

An iPhone is a great example of a device that uses a GUI. We are all very used to being able to click on icons to launch our applications, to swipe up and down to see our list scroll in an animated fashion, and to long press our icons to see them wiggle back and forth to indicate that you can move them. All this is often referred to as the look and feel, and it is all at the core of the concept of a GUI.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.80.213