Hide chapters

Real-World iOS by Tutorials

First Edition · iOS 15 · Swift 5.5 · Xcode 13

Before You Begin

Section 0: 4 chapters
Show chapters Hide chapters

1. Introduction
Written by Josh Steele

When Steve Jobs introduced the iPhone in 2007, it didn’t come with a developer-facing SDK. There were no third-party native apps available. Instead, Apple directed developers to make web apps for Safari. Fast forward 14 months later, and in response to intense feedback from developers, Apple released the first iOS SDK in March 2008.

Since then, Apple has released over a dozen versions of iOS. Over that time, the following also took place:

  1. iOS Framework Additions: The development teams introduced many frameworks such as SiriKit, Game Center, CoreML and ARKit. These technologies and their associated documentation continue to grow in number each year. OK, the documentation may not grow as quickly as one would like.

  2. Objective-C to Swift: Apple migrated from Objective-C to Swift as the primary language supported by Apple for iOS development.

  3. UIKit to SwiftUI: Apple started promoting SwiftUI over UIKit for user interface development.

  4. Xcode Releases: Xcode has also grown over the years to keep up with the frameworks, devices and languages developers use to develop iOS apps.

Apps need to reach the public to be successful. In 2008, Apple announced the App Store, and at the time, it contained 500 apps. Today, over five million apps are available to users worldwide.

To support releasing apps to the App Store, Apple released App Store Connect, originally part of iTunes Connect, in 2018. Since then, Apple added features such as managing app prices, creating and managing in-app purchases, analyzing sales and trends and managing beta testers through TestFlight.

As you can imagine, iOS developers need to be familiar with many technologies, best practices and techniques to release an app today. This book doesn’t delve deep into any technology. Instead, this book helps you by providing an overview of the end-to-end processes involved in releasing an iOS app. In other words, breadth, not depth.

What is this book about?

This book has to cover a lot of topics to address the needs of a successful, real-world iOS app. They fall into the following sections:

  • Designing Real World Apps: Software engineering principles state that up-front design is vital to create code that is easy to understand and maintain, and designing for iOS is no exception.
  • Building App Features: Once a foundation is in place, you can build features from the foundation up to the user interface, where applicable. These features ideally exist independently but may send information to other features through foundation layer components.
  • Modularizing Your App: Taking features a step further, you can extract features from your main project into standalone projects and import them via tools such as CocoaPods or Swift Package Manager.
  • Enhancing the User Interface & Experience: Developing an intuitive user interface is vital for any successful app. Developing a unique user experience to keep the user engaged and returning to your app is even more important.
  • App Privacy, Maintenance & Deployment: Respecting user data privacy is a requirement for iOS apps imposed by Apple and can prompt a user to choose your app over others on the App Store. Once your app deploys, learning how to maintain your code and quickly push new releases to the store is essential to prevent your app’s ratings from plummeting.

While learning how to implement specific techniques is important - you wouldn’t have an app without implementation - this book strives to convey the “why” behind those implementations. By the end of the book, you’ll find yourself going beyond the code to have a better understanding of the techniques developers learn over time.

You’ll solve real-world problems with best practices and techniques throughout the book as you develop a single iOS app. As you implement parts of the app, you may discover that a particular technique may not be the best approach for the problem at hand. You’ll also learn what makes that approach better or worse than others.

You may realize a different approach to solving a problem or totally disagree with the presented technique. That’s good! There are usually many ways to approach and solve a problem. This book simply provides a set of best practices and techniques, not the set of best practices and techniques. What’s important here is that you get familiar with these practices and use them - or a variation of them - as you develop your next iOS app.

Who is this book for?

This book is useful for developers of all levels. The content assumes foundational knowledge of the following topics:

  • Swift: Apple’s leading language for iOS development.
  • SwiftUI: The declarative and reactive framework for user interface development.
  • Networking: The basics of networking with URLSession and its related framework classes and methods.
  • Core Data: How to create database entities and attributes as well as fetch and save data.
  • Accessibility: Designing for VoiceOver and Apple Human Interface Guidelines (HIG) best practices.
  • Unit Testing: Xcode Unit Testing and Test Driven Development.
  • Deployment: Testflight beta testing and App Store deployment.

Note: If you need to fill in gaps in your knowledge, provides a variety of books to help. To brush up on Swift and SwiftUI, Swift Apprentice and Swift UI Apprentice, are great places to start. Core Data by Tutorials takes you through the entire Core Data stack. iOS Animations by Tutorials gives you the basics to keep your app lively for your user. With iOS Test-Driven Development by Tutorials, you can learn techniques to keep your app bug-free. Finally, iOS App Distribution and Best Practices provides the best techniques for getting your app to the App Store.

As mentioned earlier, this book covers a wide breadth of topics and doesn’t go too deep into them. Instead, the focus is on why you should use these techniques and best practices to make your app successful.

The sample project

Throughout this book, you’ll work on improving a sample project called PetSave. PetSave is an adoption and fostering app that searches for animals available to you in your area. It takes into account the pet’s medical history along with your personal preferences to return results.

Open the final folder of the final chapter’s sample project to get an idea of what the app will be able to do:

The PetSave Animals Near You Results Page.
The PetSave Animals Near You Results Page.

The features you’ll work on developing or incorporating are:

  • Animals Near You: This feature uses your current location to see which pets are up for adoption near you.
  • Search: This feature lets you refine your search to particular pets or attributes you’re looking for when adopting.
  • Onboarding: On first launch, the onboarding feature will introduce the user to PetSave’s features.

While you implement those features, you’ll use iOS development best practices such as:

  • Low Coupling and High Cohesion: Designing your code to be highly cohesive within code elements while minimizing coupling between elements helps promote reuse and makes future maintenance easier.
  • Proper code structure: Structuring code elements into conceptual layers and segments helps you understand the purpose of each set of code, how they relate to one another and how you can use them when implementing parts of your app.
  • Persistence: Keeping a copy of network data on device prevents the app from reaching back out to get that data repeatedly which saves valuable resources such as the user’s data plan.
  • Modular App Features: Isolate your features into modules that can be tested and maintained separately from your main app to promote reuse and decrease the likelihood of bugs.
  • Animations and Custom Controls: Lively animations and custom controls help make a user’s experience a memorable one and keeps them coming back to use your app in the future.
  • Accessibility: Dynamic Text, proper use of colors and preparing your code for VoiceOver helps make your app accessible to a wider audience.
  • Localization: To reach a worldwide audience, you need to prepare your app for the various locales in which you’ll release it.
  • App Privacy: Asking for permission to use certain device features and advertising what user data your app collects are both required by Apple when developing an iOS app.

Now that you know what the app will look like when you finish the book, it’s time to see what you’ll start with. Open this chapter’s starter project. Build and run.

You’ll see an almost blank screen under the Animals Near You and Search tabs. You’ll populate those screens throughout the book using best practices in iOS development.

An Empty Starter Project.
An Empty Starter Project.

PetSave uses the online Petfinder API from Purina. This API gives developers the ability to search for pets that need new homes. The main Petfinder website has information on shelters and adoption agencies across the United States. If you’re looking for a new pet, you should check them out!

Signing up for an API Key

To access the Petfinder database, you must sign up for one of their free API keys. Go to the Petfinder developer website and sign up for an account:

The Petfinder Signup Page.
The Petfinder Signup Page.

After that, go back to the developer web page and click GET AN API KEY at the bottom of the page. Follow the steps to get both the API key and its corresponding secret.

Open Core/data/api/APIConstants.swift and set the clientId and clientSecret properties with the key and secret, respectively:

enum APIConstants {
  static let host = ""
  static let grantType = "client_credentials"
  static let clientId = "YourKeyHere"
  static let clientSecret = "YourSecretHere"

Don’t forget to copy over the key and secret if you use the chapter’s starter project as you progress through future chapters.

Check out the Petfinder API documentation here.

Key points

  • In this book you’ll learn techniques to create a real-world iOS app from scratch.
  • Petfinder provides an API to search for pets around you. You’ll use this API to create the PetSave iOS app throughout the coming chapters.
  • You’ll solve real-world problems with best practices and techniques throughout the book.

Where to go from here?

You’ve taken a look at how the project will start and how it looks in its final form. Now you’re ready to start adding everything that comes in between.

But you’re not ready to start writing code yet. Before you open Xcode, it’s important to understand the purpose of the app. Moreover, you need to devise a good battle plan. You need to answer questions like “What architectures should I use?”, “How should I organize my code?” and “What features should I include in the app?” before you start writing your code. In the next chapter, you’ll start to answer those questions.

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.
© 2024 Kodeco Inc.