Book Image

Swift 4 Programming Cookbook

Book Image

Swift 4 Programming Cookbook

Overview of this book

Swift 4 is an exciting, multi-platform, general-purpose programming language. Being open source, modern and easy to use has made Swift one of the fastest growing programming languages. If you interested in exploring it, then this book is what you need. The book begins with an introduction to the basic building blocks of Swift 4, its syntax and the functionalities of Swift constructs. Then, introduces you to Apple's Xcode 9 IDE and Swift Playgrounds, which provide an ideal platform to write, execute, and debug the codes thus initiating your development process. Next, you'll learn to bundle variables into tuples, set order to your data with an array, store key-value pairs with dictionaries and you'll learn how to use the property observers. Later, explore the decision-making and control structures in Swift and learn how to handle errors in Swift 4. Then you'll, examine the advanced features of Swift, generics and operators, and then explore the functionalities outside of the standard library, provided by frameworks such as Foundation and UIKit. Also, you'll explore advanced features of Swift Playgrounds. At the end of the book, you'll learn server-side programming aspect of Swift 4 and see how to run Swift on Linux and then investigate Vapor, one of the most popular server-side frameworks for Swift.
Table of Contents (9 chapters)

Using Swift Playgrounds for UI

Playgrounds are great for exploring the Swift language and the APIs available on Apple platforms, but they can also be very useful for experimenting with UI and testing custom views and interfaces. Let's build a very simple bar chart view that we can use to display numerical data in chart form, and use a playground to test it.

All the code for this chapter can be found in a GitHub repository at http://swiftbook.link/code/chapter6.

Getting ready

First, we'll create an iOS-based playground to build our bar chart. In Chapter 1, Swift Building Blocks, we went through creating a new playground, so go back there if you need a refresher.

We will create a custom view that will display information...