How Does an App Work

Howe Wu
3 min readApr 22, 2022

紀錄在 raywenderlich 上的課程

An app is essentially made up of objects

一個 App 本質上是由物件組成的

Many of the objects in your app are provided by iOS,

For example, the button which is a UIButton object

and the alert pop up which is a UIAlert conntroller object.

Some objects you have to program yourself

such as the view controller.

These objects all communicate by passing messages back and forth to each other.

When the user taps the hit me button of the app, for example, the UI button object sends a showAlert message to your view controller.

In turn your view controller may message many more objects.

Such as sending the addAction message to the UIAlert controller.

On iOS, apps are event-driven.

Which means that objects wait for certain events to occur and then process them.

an app spends most of its time doing absolutely nothing. 🙂

Just waiting for something to happen.

When the user taps the screen, the app springs to action for a few milliseconds and then it goes back to sleep again until the next event arrives.

You’re part in all of this is to write the source code for the actions to be performed when your object receives messages for such events.

As an example, lets walk through the entire process of when a user taps your hit me button.

first, the user taps the screen.

Next, iOS detects the touch and determines that the button was tapped.

So it sends the button a message saying, hey, you’ve been touched.

This is called a touch event.

Remember in the storyboard,we connected the touch up inside action on the button to our showAlert code.

So at this point, the button sends the showAlert message to our view controller.

Inside showAlert, the view controller creates a UIController object and sends the addAction message to it and to show the alert, theview controller sends the present message.

after showAlert finishes displaying the alert, it returns up the entire chain and the app goes back to sleep.

Input from the user mostly in forms of touches and taps is one of the most important sources of events for your apps.

But there are other types of events as well.

For example, the operating system will notify your app when user receives an incoming phone call or when it has to redraw the screen or when a timer has counted down and much more.

Just remember, everything your app does is triggered by some event.

因為是在講一些原理,每次都要一直點影片來看也挺麻煩的,我乾脆直接把可能是重要的是給記下來。

--

--

Howe Wu
0 Followers

一介調光師正努力轉生成 iOS 工程師