Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Swift

You're reading from   Learning Swift Build a solid foundation in Swift to develop smart and robust iOS and OS X applications

Arrow left icon
Product type Paperback
Published in Jun 2015
Publisher Packt
ISBN-13 9781784392505
Length 266 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Andrew J Wagner Andrew J Wagner
Author Profile Icon Andrew J Wagner
Andrew J Wagner
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Introducing Swift 2. Building Blocks – Variables, Collections, and Flow Control FREE CHAPTER 3. One Piece at a Time – Types, Scopes, and Projects 4. To Be or Not to Be – Optionals 5. A Modern Paradigm – Closures and Functional Programming 6. Make Swift Work for You – Protocols and Generics 7. Everything is Connected – Memory Management 8. Writing Code the Swift Way – Design Patterns and Techniques 9. Harnessing the Past – Understanding and Translating Objective-C 10. A Whole New World – Developing an App 11. What's Next? Resources, Advice, and Next Steps Index

Understanding playgrounds

A playground is not actually a program. While it does execute code like a program, it is not really useful outside of the development environment. Before we can understand what the playground is doing for us, we must first understand how Swift works.

Swift is a compiled language, which means that for Swift code to be run, it must first be converted into a form that the computer can actually execute. The tool that does this conversion is called a compiler. A compiler is itself a program and it is one way to define a programming language.

The Swift compiler accepts Swift code as input, and if it can properly parse and understand the code, it outputs machine code. Apple developed the Swift compiler to understand the code according to a series of rules. Those rules are what define the Swift programming language and what we are trying to learn when we say we are learning Swift.

Once the machine code is generated, Xcode can wrap up the machine code inside an app that users can run. However, we are running Swift code inside our playground, so building an app is clearly not the only way to run code.

Every time you make a change to a playground, it automatically tries to compile your code. If it is successful, instead of wrapping up the machine code in an app to be run later, it runs the code immediately and shows you the results. If you have to perform this process yourself, you would first have to consciously make the decision to build the code into an app and then run it when you want to test something. This would be a huge waste of time, especially if you write an error that you don't catch until the moment you decide to actually run it. The quicker you can see the result of a code change, the faster you will be at developing the code, and the fewer mistakes you will make.

For now, we will develop all of our code inside a playground because it is a fantastic learning environment. Playgrounds are even more powerful than what we have seen so far, and we will see this as we delve deeper into the Swift language.

We are just about ready to get to the meat of learning Swift, but first let's take a moment to ensure that you can get the most out of this book.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image