Journey to the App: Learn to Develop an iOS App - Part 1

This is my journey in learning to code in Swift and developing a proper iOS app. At the end of this journey, I aim to develop an application that can be released on the App Store. I have little idea what I would want to create at the end of this journey.

But we have to start somewhere first right?

Experience

The closest experience I have in developing an mobile application is in university. I took a module on mobile application and we were tasked to build an Android application that can receive and action upon the push notifications when the user stepped into a certain proximity area. My teammate and I developed a food recommendation app. When you walked into each canteen, the application will recommend you a list of food that you would possibly want to eat today. We desire to solve the #firstworldproblems when people are difficulties deciding what to have for their next meal.

I’ve zero experience in developing in Swift but I don’t think that this will become a hurdle in anyway. Good developers can develop in any language… It’s the concept that matters.

Let’s Start!

There are a few ways I can kickstart my journey.

Yeah, there are many ways to get myself started… Since I’m not very familiar with Xcode in the first place, I wanted to go through the tutorials that can get myself familiarize with the interfaces and concepts first. Anyway, that’s how I usually learn new skills and I think I should it this way again.

Beginner Resources

There are so many tutorials on the Internet. Here are a few that I’ve collected that seems to be useful in my journey:

Tutorials

Concepts

Bear in mind that some of these tutorials are already outdated… but I still think that certain concepts still matter so I’m going to put it here anyway.

Let’s Start!

I happened to be someone who doesn’t really like to use video tutorials. Don’t mind me… but it’s usually very lengthy and I just want to get to the points that I need to carry on with my work.

Apple’s tutorial in developing iOS Apps is unfortunately not updated to the latest Xcode version. However, it’s a good start to let me understand the difference between development in <iOS13 and development in >=iOS13.

Storyboard vs SwiftUI

The first difference came about when I was creating a project on Xcode. When you created a new project on Xcode, you will be prompted to click on the template that is most suitable for your new project. Here’s how the screen looks like:

In Apple’s tutorial, you are supposed to select “Single View Application” under the “Application” header on the template screen. However, I don’t see that in Xcode 12 so I suspect that they have removed or somehow collapsed this option in the new interface. Intuitively, I’ve selected “App” since this is the closest to what “Single View Application” might represent.

On the next prompt, you will be asked to fill up some details on your project. For instance, you can fill up the organisation identifier for your packages so that it will uniquely identify the origin of your project. In Xcode 12, you will be asked to select the “Interface”

So I think SwiftUI was introduced by Apple WWDC in 2019. SwiftUI is the latest framework that Apple released to build the user interfaces. It’s supposed to be simpler as compared to the past (and I’m not sure what’s the past… don’t ask me) but from the official SwiftUI website it seems like design tools are supported in the SwiftUI.

Storyboards are like what it has been named. It’s used to prototype and design different views within a single project. It allows the developer to transit between the different views (e.g. Pre-login -> Login Screen). Most of the objects that you’ve seen on the interfaces can also be added using the Object Library (e.g. text field, button).

This kinds of resembles the user interface design that Visual Studio C# has provided. Once you have added an object on the interface, you will be able to add additional actions to the object (e.g. click on it and do some actions).

Which one to use first?

From what I’ve tried to understand, it seems like Storyboard is supposed to be much easier as it “hides” many information in the background. SwiftUI seems to be much more powerpack and many experienced developers are advised to start with SwiftUI instead.

I wanted to follow the Apple tutorial so I think I will stick to the Storyboard first.

Resources used for this Section

AppDelegate vs AppDelegate + SceneDelegate

I was trying to understand the functions in AppDelegate.swift after I’ve created my first project. Some delegate methods that are mentioned in the tutorial are no longer available in the same file.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
func applicationWillResignActive(_ application: UIApplication)
func applicationDidEnterBackground(_ application: UIApplication)
func applicationWillEnterForeground(_ application: UIApplication)
func applicationDidBecomeActive(_ application: UIApplication)
func applicationWillTerminate(_ application: UIApplication)

Instead, they are separated to a new file called SceneDelegate.swift. Instead of calling the methods with applicationXXX, they are also renamed to sceneXXX as shown below:

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions)
func sceneDidDisconnect(_ scene: UIScene)
func sceneDidBecomeActive(_ scene: UIScene)
func sceneWillResignActive(_ scene: UIScene)
func sceneWillEnterForeground(_ scene: UIScene)
func sceneDidEnterBackground(_ scene: UIScene)

Apparently in iOS 13 onwards, Apple has splited AppDelegate into AppDelegate and SceneDelegate. This seems like an important concept that I would need to understand before developing any apps on iOS.

What is AppDelegate?

According to Apple, AppDelegate is meant to be responsible for the application lifecycle and setup. This seems like the main entry point of an iOS application. There are three stubs defined in the file:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?)

This method is called after the app is launched. It happens after the launch process is almost done and when the app is almost ready. However, I’m not too sure what can be placed in this function. There must be something that this method can process before the UI windows are shown to the user.

func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions)

According to the documentation in the file, it seems like this function will be called when a “new scene session is being created”. Before creating a new scene, this method will be called first to obtain the configuration object needed to create the scene. Hence, this method can be implemented to dynamically alter the configuration data for each scene.

func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>)

This function triggers when “the user discards a scene session”. This method can be used to released any resources that are specific to the discarded scene.

What is SceneDelegate?

SceneDelegate.swift seems to be responsible for everything that’s related to the user interface. If there is a state transition, there are methods in this scene to handle the content and the effects of the user interface.

I think the methods are quite straightforward and I probably will understand them better when I started developing the application. Basically there are a few keypoints here:

Resources used for this Section

Next Step…

The next step is to create an user interface and write some codes to activate certain actions. I will be following Apple’s tutorial to create a FoodTracker application as a start. I have started to write some codes… but I think I will consolidate some tips and things that I’ve learned from this project in the next post.

Till then…