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

Blinking an LED with the SBDigitalGPIO type


Before we do any programming we will need to collect the hardware components needed for this project and connect them together. For this project you will need the following components:

  • 100 ohm resistor

  • 3mm or 5mm LED

  • Breadboard

  • Jumper wire

  • BeagleBone Black

The following fritzing diagram shows how we would wire the components for this project:

We will start off by using a black jumper wire to connect pin 1 of the P9 expansion header, which is ground, to the ground rail on the breadboard. Then, use a red jumper wire to connect pin 3 of the P9 expansion header, which is 3.3V, to the power rail on the breadboard. When we wire electronic components, we use red wires to indicate power and black wires to indicate ground.

For this circuit we will want to connect the cathode end of the LED (the shorter leg of the LED) to the ground rail and the anode end of the LED to one end of the 100 ohm resistor. We then run a third jumper wire from pin 12 of the P9 expansion...