Swift Introduction/Introduction

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Introduction[edit | edit source]

What is Swift?[edit | edit source]

Swift is an open source programming language, introduced by Apple in 2014. It is used for their operating systems macOS for desktops and iOS for mobile devices, for instance iPhone or iPad. Since 2015 Swift has also been available on Linux under the Apache Licence 2.0[1]. It is a modern language that includes multiple paradigms like object orientation, functional- and imperative programming. Apple included useful features from other languages like C#, Ruby, Python or Haskell.

Swift on Linux[edit | edit source]

Install[edit | edit source]

Before you can start with Swift, you first have to download and install the compiler and other components[2]. Those can be downloaded from Swift's download page. On Linux, clang[3] has to be installed too using following command:

$ sudo apt-get install clang

IDE for Linux[edit | edit source]

Xcode is only available on macOS. However, there are alternatives which provide similar functionality:

  • JetBrain's CLion offeres a Swift extension which features code highlighting and completion and also a debugger[4].
  • The Open-Source Editor Atom offeres a plugin that works similar to Xcode's playground where you can easily try new code and immediatly see what it does[5].

First example[edit | edit source]

Before we dive right into Swift's basic and advanced features, let's have a look at the world-famous "Hello World" example.

print("Hello World")

Now, let's have a first glance at what variables and constants look like.

var name: String = "John"
let greeting: String = "Welcome to the world of Swift, "
print(greeting + name)
// Welcome to the world of Swift, John

References[edit | edit source]

  1. Apache Software Foundation [online][accessed: 18.09.2017] | https://www.apache.org/licenses/LICENSE-2.0
  2. Swift.org [online][accessed: 18.09.2017] | https://swift.org/getting-started/
  3. clang [online][accessed: 18.09.2017] | https://clang.llvm.org
  4. JetBrain Swift Plugin [online][accessed: 18.09.2017] | https://blog.jetbrains.com/clion/2015/12/swift-plugin-for-clion/
  5. Atom.io Swift Playground [online][accessed: 18.09.2017] | https://atom.io/packages/swift-playground