Book Image

Mastering Swift 3 - Linux

By : Jon Hoffman
Book Image

Mastering Swift 3 - Linux

By: Jon Hoffman

Overview of this book

Swift is a modern, fast, and safe programming language created by Apple. Writing Swift is interactive and fun, the syntax is concise yet expressive, and the code runs lightning-fast. Swift’s move to open source has been embraced with open arms and has seen increased adoption in the Linux platform. Our book will introduce you to the Swift language, further delving into all the key concepts you need to create applications for desktop, server, and embedded Linux platforms. We will teach you the best practices to design an application with Swift 3 via design patterns and Protocol-Oriented Programming. Further on, you will learn how to catch and respond to errors within your application. When you have gained a strong knowledge of using Swift in Linux, we’ll show you how to build IoT and robotic projects using Swift on single board computers. By the end of the book, you will have a solid understanding of the Swift Language with Linux and will be able to create your own applications with ease.
Table of Contents (24 chapters)
Mastering Swift 3 - Linux
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
2
Learning About Variables, Constants, Strings, and Operators

Tuples


Tuples group multiple values into a single compound value. Unlike arrays and dictionaries, the values in a tuple do not have to be of the same type. While we are including the tuple in the chapter on collections, they really are not a collection; they are more like a type.

The following example shows how to define a tuple:

var team = ("Boston", "Red Sox", 97, 65, 59.9) 

In the preceding example, we created an unnamed tuple that contains two strings, two integers, and one double. We can decompose the values from this tuple into a set of variables, as shown in the following example:

var team = ("Boston", "Red Sox", 97, 65, 59.9) 
var (city, name, wins, loses, percent) = team 

In the preceding code, the city variable will contain Boston, the name variable will contain Red Sox, the wins variable will contain 97, the loses variable will contain 65, and, finally, the percent variable will contain 0.599.

We could also retrieve the values from a tuple by specifying the location of the value....