Basics of iOS Application Development - Beginning DevOps On AWS For iOS Development - Xcode, Jenkins, and Fastlane Integration On The Cloud
Basics of iOS Application Development - Beginning DevOps On AWS For iOS Development - Xcode, Jenkins, and Fastlane Integration On The Cloud
To develop iOS apps, Apple provides several tools and resources. iOS apps can be developed in native pro‐
gramming languages such as Swift or Objective-C and other cross-platform languages.
In this chapter, I will cover the requirements and basic building blocks of iOS application development
while also walking you through the procedure by building a sample application with Swift and testing the
application on an iOS device and iOS simulators.
Development Requirements
As an iOS developer, you need a macOS device and an Apple developer account to start development.
Mac
To start iOS development, a Mac is required. It is available in both notebook and desktop versions. The current notebook
versions are MacBook Air and MacBook Pro, and the desktop versions are iMac, Mac Pro, and Mac mini. Some of the Mac
models can be seen in Figure 1-1.
You can register as an Apple developer for free. All you need is an Apple ID. With the free developer ac‐
count, you will have access to install Xcode on your Mac (which we will cover in the next section), iOS de‐
velopment documentations, sample code, Apple developer forums, and bug reporting. You will also be
able to test your apps on devices. The free Apple developer account is sufficient for local testing and de‐
velopment. However, to distribute apps, you will need to enroll in the Apple Developer Program.
The Apple Developer Program is a paid membership program which is billed yearly. It is required if you are interested in
creating apps for distribution on the App Store. More details on the Apple Developer Program can be found on the Apple
website as seen in Figure 1-2.
Swift
Swift is a programming language developed by Apple in 2014. The aim of developing Swift was to find a
replacement for C-based languages such as C, C++, and Objective-C. With the expressive nature of its syn‐
tax, Swift has modern features developers want, and it makes iOS application development easier.
There are various resources available to learn Swift; however, Swift Playgrounds, an app developed by Apple, allows you
to learn Swift in a fun and interactive way. Currently the app is available for iPad and Mac and can be downloaded from the
App Store, as seen in Figure 1-3.
Introduction to Xcode
In addition to enabling development on MacOS systems, Xcode is an integrated development environ‐
ment (IDE) developed by Apple and it has all you need to start iOS development across all Apple OS plat‐
forms. It includes features such as a code editor, debugger, etc. It also comes with a simulator which en‐
ables you to build and test your application on real iOS devices without needing a physical iOS device.
In the following sections, I will show you how to install Xcode and use it to build and deploy an iOS
application.
Installing Xcode 12
I will be installing Xcode 12 on macOS Big Sur, which are currently the latest versions of Xcode and macOS, respectively.
To install, go to the App Store on your Mac and search for Xcode, as seen in Figure 1-4.
If you get an error like “Xcode can’t be installed on “Macintosh HD” because macOS version X or lat‐
er is required," update your macOS before trying to install.
After installation, launch Xcode and you should see a welcome page, as seen in Figure 1-5.
Next, I will show you how to use Xcode for app creation by creating a sample application.
Creating an Application
With Xcode installed, you are ready to start building iOS apps. I will start by using an app template which
is provided by Xcode and then add a custom code to customize the application.
iOS Application Template
Xcode provides sample templates that make it easy to get started building apps. These templates can be accessed by creating
a new Xcode project (Figure 1-5) and the different available templates are displayed. For the sample app I am building, I will
choose iOS and App, as shown in Figure 1-6.
If this is your first time using Xcode, there will be a prompt to sign in with an Apple ID, as shown in Figure 1-7.
After signing in and linking an Apple ID to Xcode, there will be a prompt to configure the details for your new Xcode
project. An example is shown in Figure 1-8.
Figure 1-8 Filling in details for new Xcode project
A folder location on the workstation to save the app must be selected before creation. Once complete, an app is created,
as seen in Figure 1-9.
As seen in Figure 1-9, the application template is written in Swift language since Swift was selected as the
language when creating the project in Figure 1-8.
Let us look at the out-of-the-box Swift code and see what it is doing.
import SwiftUI
struct ContentView: View {
var body: some View {
Text("Hello, world!")
.padding()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Listing 1-1 ContentView.swift
The code snippet in Listing 1-1 is responsible for the view that shows up on the iOS device; as seen, this iOS app
template simply prints out “Hello, world!”.
import SwiftUI
@main
struct SampleAppApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Listing 1-2 SampleAppApp.swift
Listing 1-2 shows the entry point of the app, and as seen, it runs the application by calling ContentView()
(defined in a different file ContentView.swift), which is shown in Listing 1-1.
Selecting SwiftUI interface when configuring the project enables live previews of the app as changes are
being made to the content view in code.
Let us look at a preview of the default app. From the run destination menu, select the iOS simulator you want to use, as
seen in Figure 1-10.
The iPhone 11 simulator is selected, and the preview is shown on a simulated iPhone 11 as shown in Figure 1-11. As
shown, live preview gives you the ability to see what the app view looks like before running a build. As changes are made to
the app view in code, the preview is also updated.
Until this point, you have been working with the default app provided as part of the template selected
when creating an Xcode project, now let’s add a custom Swift code.
import SwiftUI
struct ContentView: View {
@State private var date = Date()
let dateRange: ClosedRange<Date> = {
let calendar = Calendar.current
The sample app is a simple dummy calendar app that lets you select a date and a time within that date.
Next, you will add an icon for this application.
An app icon is the visual representation of an app that is displayed on the home screen, the App Store, and various other
places such as settings and search results. Due to the varied usage, different sizes of the app icon are required by Apple.
Example icons for this app can be downloaded from GitHub at https://github.com/abdulola/de‐
vops-on-aws-ios-development/tree/main/Chapter_1/AppIcons.
App icons can be added by accessing Assets.xcassets and dragging the icons into their respective slots, as shown in
Figure 1-12.
Building an Application
We’ve created a custom sample application code and added an icon for the application. We have all the
basic building blocks of the application in place. Now we will build the application and run it on iOS
devices.
Building on a Physical iPhone
Let us look at what the application looks like on a physical iOS device, such as an iPhone.
To build an application on a physical iPhone, it must be plugged into the Mac workstation used for development. Once
the device is plugged into the workstation, it can be selected as a build destination. An example is shown in Figure 1-13.
To start building on a connected physical iOS device, click the play sign button to the left of the device selection (Figure
1-13). An iOS keychain prompt might be shown, as seen in Figure 1-14. This requires the Mac workstation password (not
your Apple ID password).
You will be required to add your Apple account to Xcode under Xcode ➤ Preferences to set up an
Apple development team.
Make sure your iPhone is unlocked for Xcode to connect to it and install the Sample App. If this your
first time plugging your iPhone to the Mac workstation, you will get a prompt to trust the workstation.
You might also be required to trust the app developer from your iPhone by going to Settings ➤
General ➤ Device Management.
Figure 1-14 Apple keychain login prompt
Once the build is complete, the new app with its icon can be found installed on the iPhone.
Figure 1-15 shows an example UI of the app when launched on a physical iPhone.
Just like building and running the application on a physical device, let’s run the application on a simula‐
tor.
To build on a simulator, the target device simulator should be selected just like how the physical iOS de‐
vice was selected, and to start building, click the play sign button to the left of the device selection, as
shown in Figure 1-13.
Once the build is complete, the simulator will show the simulated iPhone with the app installed on it. Use your cursor to
scroll through the pages of the simulated iPhone and launch the installed application. Figure 1-16 shows the icon of the
application and what it looks like when launched on an iPhone 11 simulator.
So far, I have shown you how to build applications using the Xcode user interface; however, you can also
interact with Xcode through the command line interface using its command line tool xcodebuild .
xcodebuild allows you to perform tasks such as building, testing, and archiving on your Xcode projects
from the command line. With it, you can perform all the tasks we did earlier from the user interface on
the command line, which opens the door for automation.
It comes preinstalled with Xcode so there is no additional action to install it on your macOS workstation. Run
xcodebuild -usage command on your workstation to see some basic usage information, as seen in Listing 1-4.
$ xcodebuild -usage
Usage: xcodebuild [-project <projectname>] [[-target <targetname>]...
xcodebuild [-project <projectname>] -scheme <schemeName> [-destination <destinationspecifier>]...
xcodebuild -workspace <workspacename> -scheme <schemeName> [-destination <destinationspecifier>].
xcodebuild -version [-sdk [<sdkfullpath>|<sdkname>] [-json] [<infoitem>] ]
xcodebuild -list [[-project <projectname>]|[-workspace <workspacename>]] [-json]
xcodebuild -showsdks [-json]
Listing 1-4 xcodebuild -usage truncated output
To see more usage details including all available options, run xcodebuild -help and see the output, shown in Listing
1-5.
$ xcodebuild -help
Usage: xcodebuild [-project <projectname>] [[-target <targetname>]...
...
xcodebuild -version [-sdk [<sdkfullpath>|<sdkname>] [-json] [<infoitem>] ]
xcodebuild -list [[-project <projectname>]|[-workspace <workspacename>]] [-json]
xcodebuild -showsdks [-json]
...
Options:
-usage print brief usage
-help print complete usage
-verbose provide additional status output
-license show the Xcode and SDK license agreements
-checkFirstLaunchStatus Check if any First Launch tasks need to be performed
-runFirstLaunch install packages and agree to the license
-project NAME build the project NAME
-target NAME
...
Listing 1-5 xcodebuild -help truncated output
You can use xcodebuild to navigate through the sample application created in the earlier sections, as
seen in Listings 1-6 and 1-7.
First, you can list all the information about the sample application project.
You must be within the project and workspace directory to run the following commands.
Summary
This chapter showed you the basic building blocks of iOS application development; you got hands-on ex‐
perience by building your own application and deploying it onto an actual iOS device and iOS simulator.
In the next chapter, we will take this one step further and explore how you can submit this built applica‐
tion to the App Store Connect for distribution and/or eventual submission to Apple’s App Store.