© Yanis Zafirópulos 2019
Yanis ZafirópulosSwift 4 Recipeshttps://doi.org/10.1007/978-1-4842-4182-0_2

2. Basics

Yanis Zafirópulos1 
(1)
Granada, Spain
 

In this chapter, we will look into some basic constructs and conventions of the Swift programming language and help you get started writing your first program.

2.1 Create a Hello World

Problem

I want to write a Hello World program and write my first Swift program.

Solution

A single line does the trick. Hello World!
print("Hello World!")

How It Works

All we have to write is a single line of code, using the print function.
Hello World!

2.2 Declare variables

Problem

We want to declare some variables.

Solution

Declare a variable, without type.
var surname = "Doe"
Declare a variable, with type.
var fullName : String = "John ...

Get Swift 4 Recipes: Hundreds of Useful Hand-picked Code Snippets now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.