Book Image

iOS 14 Programming for Beginners - Fifth Edition

By : Ahmad Sahar
Book Image

iOS 14 Programming for Beginners - Fifth Edition

By: Ahmad Sahar

Overview of this book

If you're looking to work and experiment with powerful iOS 14 features such as widgets and App Clips to create your own apps, this iOS programming guide is for you. The book offers a comprehensive introduction for experienced programmers who are new to iOS, taking you through the entire process of learning the Swift language, writing your own apps, and publishing them on the App Store. Fully updated to cover the new iOS 14 features, along with Xcode 12 and Swift 5.3, this fifth edition of iOS 14 Programming for Beginners starts with an introduction to the Swift programming language and shows you how to accomplish common programming tasks with it. You'll then start building the user interface (UI) of a complete real-world app using the storyboards feature in the latest version of Xcode and implement the code for views, view controllers, data managers, and other aspects of mobile apps. The book will also help you apply iOS 14 features to existing apps and introduce you to SwiftUI, a new way to build apps for all Apple devices. Finally, you’ll set up testers for your app and understand what you need to do to publish your app on the App Store. By the end of this book, you'll not only be well versed in writing and publishing applications, but you’ll also be able to apply your iOS development skills to enhance existing apps.
Table of Contents (31 chapters)
1
Section 1: Swift
10
Section 2:Design
15
Section 3:Code
24
Section 4:Features

Running the app in the iOS simulator

The iOS simulator is installed when you install Xcode. It provides a simulated iOS device so that you can see what your app looks like and how it behaves, without needing a physical iOS device. It can model all the screen sizes and resolutions for both the iPad and iPhone so you can test your app on multiple devices easily.

To run your app in the simulator, follow these steps:

  1. Click the Scheme menu in the toolbar and you will see a list of simulators. Choose iPhone SE (2nd generation) from this menu:
    Figure 1.10 – Xcode Scheme menu with iPhone SE (2nd generation) selected

    Figure 1.10 – Xcode Scheme menu with iPhone SE (2nd generation) selected

  2. Click the Play button to install and run your app on the currently selected simulator. You can also use the Command + R keyboard shortcut.
  3. If you see the Developer Tools Access dialog box, enter the username and password of the Mac's administrator account and click Continue.
  4. The simulator will launch and show a representation of an iPhone SE (2nd generation). Your app displays a white screen, as you have not yet added anything to your project:
    Figure 1.11 – iOS simulator

    Figure 1.11 – iOS simulator

  5. Switch back to Xcode and click on the Stop button (or press Command + .) to stop the currently running project.

You have just created and run your first iOS app in the simulator! Great job!

If you look at the Scheme menu, you may wonder what the No Devices and Build sections are for. Let's take a look at them in the next section.

Understanding the No Devices and Build sections

You learned how to choose a simulator in the Scheme menu to run your app in the previous section. In addition to the list of simulators, the Scheme menu also has No Devices and Build sections. These allow you to run apps on actual iOS devices, and prepare apps for submission to the App Store.

Click the Scheme menu in the toolbar to see the No Devices and Build sections at the top of the menu:

Figure 1.12 – Xcode Scheme menu with Any iOS Device (arm64) selected

Figure 1.12 – Xcode Scheme menu with Any iOS Device (arm64) selected

The No Devices section currently displays text stating No devices connected to 'My Mac'... because you currently don't have any iOS devices connected to your computer. If you were to plug in an iOS device, it would appear in this section, and you would be able to run the apps you develop on it for testing. Running your apps on an actual device is recommended as the simulator will not accurately reflect the performance characteristics of an actual iOS device, and does not have some hardware features and software APIs that actual devices have.

The Build section has only one menu item, Any iOS Device (arm64). This is used when you need to archive your app prior to submitting it to the App Store. You'll learn how to do this in the final chapter of this book.

Now, let's see how to build and run your app on an actual iOS device. The vast majority of the instructions in this book do not require you to have an iOS device though, so if you don't have one, skip the next section and go straight to Chapter 2, Simple Values and Types.