Chapters

Hide chapters

iOS Apprentice

Eighth Edition · iOS 13 · Swift 5.2 · Xcode 11

My Locations

Section 4: 11 chapters
Show chapters Hide chapters

Store Search

Section 5: 13 chapters
Show chapters Hide chapters

1. Introduction
Written by Joey deVilla

Hi, welcome to The iOS Apprentice: Beginning iOS Development with Swift, Eighth Edition, the swiftest way (pardon the pun) to iOS development mastery!

In this book, you’ll learn how to make your own iPhone and iPad apps using Apple’s Swift programming language, Xcode 11, and the SwiftUI and UIKit user interface frameworks. You’ll do this by building four interesting iOS apps.

The apps you’ll make in The iOS Apprentice
The apps you’ll make in The iOS Apprentice

Everybody likes games, right? So you’ll start by building a simple but fun iPhone game named Bullseye that will teach you the basics of iPhone programming. The other apps will build on what you learn there.

Taken together, the four apps that you’ll build cover everything you need to know to make your own apps. By the end of the book, you’ll be experienced enough to turn your ideas into real apps that you can put on the App Store!

If you’ve never programmed before or you’re new to iOS, don’t worry. You should be able to follow along with the step-by-step instructions and understand how to make these apps. Each chapter has a ton of illustrations to keep you from getting lost. Not everything might make sense right away, but hang in there and all will become clear in time.

Writing your own iOS apps is a lot of fun, but it’s also hard work. If you have the imagination and perseverance, there’s no limit to what you can make your apps do. It’s my sincere belief that this book can turn you from a complete newbie into an accomplished iOS developer, but you do have to put in the time and effort. By writing this book, I’ve done my part. The rest is up to you…

About this book

The iOS Apprentice will help you become an excellent iOS developer, but only if you let it. Here are some tips that will help you get the most out of this book.

Learn through repetition

You’re going to make several apps in this book. Even though the apps are quite simple, you may find the instructions hard to follow at first — especially if you’ve never done any computer programming before. You’ll be facing a lot of new concepts.

It’s OK if you don’t understand everything right away, as long as you get the general idea. As you proceed through the book, you’ll go over many of those concepts again and again until they solidify in your mind.

Follow the instructions yourself

It’s important that you not just read the instructions, but also actually follow them. Open Xcode, type in the source code fragments and run the app in the simulator as instructed. This helps you to see how the app develops, step by step.

Even better, play around with the code and with the Xcode settings. Feel free to modify any part of the app and see what the results are. Make a small change to the code and see how it affects the entire app. Experiment and learn! Don’t worry about breaking stuff — that’s half the fun. You can always find your way back to the beginning. But better still, you might even learn something from simply breaking the code and learning how to fix it.

If you try everything but are still stuck, drop by the forums for this book at forums.raywenderlich.com. I’m around most of the time and will be happy to answer any questions related to the book and issues you might have run into.

Don’t panic — bugs happen!

You’ll run into problems, guaranteed. Your programs will have strange bugs that will leave you stumped. Trust me, I’ve been programming for 30 years and that still happens to me, too. We’re only humans and our brains have a limited capacity to deal with complex programming problems. In this book, I’ll give you tools for your mental toolbox that will allow you to find your way out of any hole you’ve dug for yourself.

Understanding beats copy-pasting

Too many people attempt to write iOS apps by blindly copy-pasting code that they find on blogs and other websites, without really knowing what that code does or how it should fit into their programs.

There’s nothing wrong with looking on the web for solutions — I do it all the time — but I want to give you the tools and knowledge to understand what you’re doing and why. That way, you’ll learn more quickly and write better programs.

This is hands-on, practical advice, not a bunch of dry theory (although we can’t avoid some theory). You’re going to build real apps right from the start, and I’ll explain how everything works along the way, with lots of images to illustrate what is going on.

I’ll do my best to make it clear how everything fits together, why we do things a certain way and what the alternatives are.

Do the exercises

I’ll also ask you to do some thinking of your own — yes, there are exercises! It’s in your best interest to actually do these exercises. There’s a big difference between knowing the path and walking the path… And the only way to learn programming is to do it.

I encourage you to not just do the exercises but also to play with the code you’ll be writing. Experiment, make changes, try to add new features. Software is a complex piece of machinery and to find out how it works, you sometimes have to put some spokes in the wheels and take the whole thing apart. That’s how you learn!

Have fun!

Last but not least, remember to have fun! Step by step, you’ll build your understanding of programming while making fun apps. By the end of this book, you’ll have learned the essentials of Swift, the iOS Software Development Kit (SDK) and both the SwiftUI and the UIKit frameworks. More importantly, you should have a pretty good idea of how everything goes together and how to think like a programmer.

This book has one ultimate goal: That by the time you reach the end, you’ll have learned enough to stand on your own two feet as a developer. We’re confident that, eventually, you’ll be able to write any iOS app that you want as long as you understand the basics. You still may have a lot to learn but, when you’re through with The iOS Apprentice, you can do it without the training wheels.

Is this book right for you?

Whether you’re completely new to programming or you come from a different programming background and want to learn iOS development, this book is for you!

If you’re a complete beginner, don’t worry — this book doesn’t assume you know anything about programming or making apps. Of course, if you do have programming experience, that helps. Swift is a new programming language but, in many ways, it’s similar to other popular languages such as Python, C# or JavaScript.

If you’ve tried iOS development before with the old language, Objective-C, then its low-level nature and strange syntax may have put you off. Well, there’s good news: Now that we have a modern language in Swift, iOS development has become a lot easier to pick up.

This book can’t teach you all the ins and outs of iOS development. The iOS SDK is huge and grows with each new release, so there’s no way we can cover everything. Fortunately, we don’t need to. You just need to master the essential building blocks of Swift and the iOS SDK. Once you understand these fundamentals, you can easily figure out how the other parts of the SDK work and learn the rest on your own terms.

The most important thing I’ll teach you is how to think like a programmer. That will help you approach any programming task, whether it’s a game, a utility, a mobile app that uses web service or anything else you can imagine.

As a programmer, you’ll often have to think your way through difficult computational problems and find creative solutions. By methodically analyzing these problems, you’ll be able to solve them, no matter how complex. Once you possess this valuable skill, you can program anything!

iOS 13 and later only

The code in this book is written exclusively for iOS version 13 and later. Each new release of iOS is such a big departure from the previous one that it doesn’t make sense to keep developing for older devices and iOS versions. Things move quickly in the world of mobile computing!

Most iPhone, iPod touch and iPad users are quick to upgrade to the latest version of iOS anyway, so you don’t need to be too worried that you’re leaving potential users behind.

Owners of older devices may be stuck with older iOS versions, but this is only a tiny portion of the market. The cost of supporting these older iOS versions for your apps is usually greater than the handful of extra customers it brings you.

It’s ultimately up to you to decide whether it’s worth making your app available to users with older devices, but my recommendation is that you focus your efforts where they matter most. Apple, as a company, relentlessly looks towards the future — if you want to play in Apple’s back yard, it’s wise to follow its lead. So back to the future it is!

What you need

It’s a lot of fun to develop for the iPhone and iPad but, like most hobbies (or businesses!), it will cost some money. Of course, once you get good at it and build an awesome app, you’ll have the potential to make that money back many times.

You’ll have to invest in the following.

An iPhone, iPad or iPod touch. I’m assuming that you have at least one of these. iOS 13 runs on the following devices:

  • iPhone 6s or newer
  • iPad Pro (any generation)
  • iPad 5th generation or newer
  • iPad Air 2 or 3rd generation
  • iPad Mini 5th generation
  • iPod Touch 7th generation

If you have an older device, then this is a good time to think about getting an upgrade. But don’t worry if you don’t have a suitable device: You can do most of your testing on iOS Simulator.

Note: Even though this book is about developing apps for the iPhone, everything within applies equally to the iPad and iPod touch. Aside from small hardware differences, these devices use iOS or its close cousin iPadOS and you program them in exactly the same way. You should also be able to run the apps from this book on your iPad or iPod touch without problems.

A Mac computer with an Intel processor: Any Mac that you’ve bought in the last few years will do, even a Mac mini or MacBook Air. It needs to have at least macOS 10.14.4 Mojave, and I strongly recommend that you use macOS 10.15 Catalina, especially when building apps with SwiftUI.

Xcode, the development environment for iOS apps, is a memory-hungry tool. These days, even the most inexpensive MacBook Air in the Apple Store comes with 8GB of RAM. You should consider this the minimum RAM for development. Keep this general rule in mind: The more RAM, the better. A smart developer invests in good tools!

With some workarounds, it’s possible to develop iOS apps on a Windows or a Linux machine, or on a regular PC that has macOS installed (a “Hackintosh”). If you’re up for a challenge, you can try iOS development on these machines, but you’ll save yourself a lot of time and hassle by just getting a Mac.

If you can’t afford to buy the latest model, then consider getting a second-hand Mac from eBay or some other resale vendor. It should be a Mac that dates from mid-2012 or later; just make sure it meets the minimum requirements (Intel CPU, preferably with more than 4 GB RAM). If it helps, you should know that the code for the SwiftUI portions of this book was written using a mid-2014 MacBook Pro with 16GB of RAM. Should you happen to buy a machine that has an older version of macOS, you should upgrade to the latest version of the operating system from the online Mac App Store for free.

Eventually, an Apple Developer Program account: You can download all the development tools for free and you can try out your apps on your own iPhone, iPad or iPod touch while you’re developing, so you don’t have to join the Apple Developer Program just yet. But to submit finished apps to the App Store, you’ll have to enroll in the paid Developer Program. This will cost you $99 per year.

See developer.apple.com/programs/ for more info.

Xcode

The first order of business is to download and install Xcode and the iOS SDK.

Xcode is the development tool for iOS apps. It has a text editor where you’ll type your source code and a visual editor for designing your app’s user interface.

Xcode transforms the source code that you write into an executable app and launches it in the iOS Simulator or on your iPhone. Because no app is bug-free, Xcode also has a debugger that helps you find defects in your code. Unfortunately, it won’t automatically fix them for you; that’s still something you have to do yourself.

You can download Xcode for free from the Mac App Store (apple.co/2wzi1L9). This requires at least macOS High Sierra (10.14.4). If you’re still running an older version of macOS, you’ll first have to upgrade to the latest version of macOS (also available for free from the Mac App Store). Get ready for a big download, as the full Xcode package is almost 8 GB.

Important: You may already have a version of Xcode on your system that came pre-installed with your version of macOS. That version could be hopelessly outdated, so don’t use it. Apple puts out new releases on a regular basis and you always want to develop with the latest Xcode and the latest available SDK on the latest version of macOS.

This revision of the book was written using Xcode version 11 and the iOS 13 SDK on macOS Catalina (10.15) beta. By the time you read this, the version numbers might have gone up again.

We’ll do our best to keep the PDF versions of the book up-to-date with new releases of the development tools and iOS versions, but don’t panic if the screenshots don’t correspond 100% to what you see on your screen. In most cases, the differences will be minor.

Many older books and blog posts (anything before 2010) talk about Xcode 3, which is radically different from Xcode 11. If it predates the iPad, it’s seriously out of date.

More recent materials may mention Xcode versions 4 through 10, which are similar to Xcode 11 but differ in many of the details. Xcode 11 also introduces a new framework, SwiftUI, and you won’t find anything about it in older tutorials.

If you’re reading an article and you see a picture of Xcode that looks different from yours, the author might be writing about an older version. You may still be able to get something out of those articles, as the programming examples are still valid. It’s just Xcode that is slightly different.

What’s ahead: An overview

The iOS Apprentice is spread across four apps, and moves from beginning to intermediate topics. You’ll build each app from start to finish, from scratch! Let’s take a look at what’s ahead.

Building apps with SwiftUI

You’ll build the first two apps using the newly-announced SwiftUI framework. Announced in 2019 at Apple’s WWDC (World Wide Developer Conference), it’s a completely different way for developers to design apps. Since it looks like SwiftUI will eventually become the preferred way to build apps, we decided to introduce it to you with your first two apps.

App 1: Bullseye

You’ll start by building a game called Bullseye. You’ll learn how to use Xcode, Swift and SwiftUI in a way that’s easy to understand.

App 2: Checklist

For your next trick, you’ll create your own to-do list app. You’ll learn more about SwiftUI, the fundamental design patterns that all iOS apps use, data structures, sharing information between objects, and saving the user’s information. Now you’re making apps for real!

Building apps with UIKit

From the very first iPhone OS and all the way up to iOS 12, iOS apps were written using Apple’s original user interface framework, UIKit. With over a decade’s worth of UIKit-based code, documentation and tutorials, today’s iOS developers can’t rely on SwiftUI alone – they’ll have to know both user interface frameworks. That’s why you’ll build the next two apps with UIKit.

App 3: MyLocations

For your third app, you’ll develop a location-aware app that lets you keep a list of spots that you find interesting. In the process, you’ll learn about UIKit, Core Location, Core Data, Map Kit and much more!

App 4: StoreSearch

Mobile apps often need to talk to web services, and that’s what you’ll do in your final app. You’ll make a stylish app that lets you search for products on the iTunes store using HTTP requests and JSON.

Let’s get started and turn you into a full-fledged iOS developer!

The language of the computer

The iPhone may pretend that it’s a phone, but it’s really a pretty advanced handheld computer that happens to have the ability to make phone calls. Like any computer, the iPhone works with ones and zeros. When you write software to run on the iPhone, you somehow have to translate the ideas in your head into those ones and zeros so that the computer can understand you.

Fortunately, you don’t have to write any ones and zeros yourself. That would be a bit too much to ask of the human brain. On the other hand, everyday English — or any other natural human language — just isn’t precise enough to use for programming computers.

So you’ll use an intermediary language, Swift. It’s a little bit like English, and reasonably straightforward for us humans to understand. At the same time, it’s ordered and structured enough so that it can be easily translated into something the computer can understand as well.

This is an approximation of the language that the computer speaks:

Actually, what the computer sees is this:

The movl and calll instructions are part of what’s called assembly language, which is just there to make machine code more readable for humans. I don’t know about you, but for me, it’s still hard to make much sense out of it.

It certainly is possible to write programs in that arcane language. In the days of 8- and 16-bit computers, if you were writing a videogame or some other app that had to eke the most performance out of those slow machines, you had to. Even today, programmers who need to work at the system level or need maximum performance from minimal hardware will write some assembly language. I’ll take having my apps run fractions of a second slower if I can write programs that I can follow because they look like this:

func handleMusicEvent(command: Int, noteNumber: Int, velocity: Int) {

  if command == NoteOn && velocity != 0 {
    playNote(noteNumber + transpose, velocityCurve[velocity] / 127)

  } else if command == NoteOff || 
           (command == NoteOn && velocity == 0) {
    stopNote(noteNumber + transpose, velocityCurve[velocity] / 127)

  } else if command == ControlChange {
    if noteNumber == 64 {
      damperPedal(velocity)
    }
  }
}

The above code snippet is from a sound synthesizer program. It looks like something that almost makes sense. Even if you’ve never programmed before, you can sort of figure out what’s going on. It’s almost English.

Swift is a hot new language that combines traditional object-oriented programming with aspects of functional programming. Fortunately, it has many things in common with other popular programming languages, so if you’re already familiar with C#, Python, Ruby or JavaScript, you’ll feel right at home with Swift.

Swift isn’t the only option for making apps. Until recently, iOS apps were programmed in Objective-C, which first appeared in 1984. Objective-C is an object-oriented extension of the tried-and-true C programming language, which was first released in 1972. Objective-C comes with a lot of ’70s and ’80s baggage and doesn’t have a lot of the niceties that modern developers have come to expect. That’s why Apple created a new language.

Objective-C will still be around for a while, but the future of iOS development is Swift. All the cool kids are using it already.

C++ is another language that adds object-oriented programming to C. It’s very powerful but, as a beginning programmer, you probably want to stay away from it. I only mention it because you can also use C++ to write iOS apps. There’s also an unholy marriage of C++ and Objective-C named Objective-C++ that you may come across from time to time. If you see it, back away slowly and don’t make eye contact.

I could have started The iOS Apprentice with an in-depth exploration of the features of Swift, but this is a tutorial, not a sleep aid! So, instead, I’ll follow the adage of “Show, don’t tell” and explain the language as we go along, very briefly at first, but in more depth later.

In the beginning, the general concepts — what is a variable, what is an object, how do you call a method, and so on — are more important than the details. Slowly but surely, all the arcane secrets of the Swift language will be revealed to you!

Are you ready to begin writing your first iOS app?

Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.
© 2026 Kodeco Inc.