How Does An App Work
How Does An App Work
And before we get started digging in and building apps the first thing I want to talk about is how exactly 3
Because we'll have it in our phones we use it to do really important things like banking and contacting 5
friends. 6
But there are actually very few people who know just exactly how an app actually works. 7
Now the first thing we have to realize is that smartphones are actually no different from just any other 9
computer and an app is just code that we write to tell that mini computer what it should do. 10
So let's say we have an app that just has a single button on it that says Click me when the user taps 11
Then the sensors in the phone register that tap and sends a message to the operating system which in 13
Now the operating system then looks at the data that it gets from the sensor including things such as 15
how much pressure was applied onto the phone at which location on the phone screen did it register that
16
pressure and a whole bunch of different things and a whole lot of numbers. 17
But the operating system takes all of those numbers and makes sense of it. 18
And once it does then it will know that this particular button on the screen of this particular app 19
was tapped at this time point and then he'll send a message to the app in question telling it that hey 20
So essentially as an app developer you're planning out all of the scenarios and what should happen. 28
In each case was almost a bit like emergency planning if the building is on fire. 29
Well we should probably evacuate the staff and we should probably shut all the doors to prevent the 31
We should show them some other pieces of information and then we'll wait to see what the user does
next. 36
And then there's a plan for how to respond to the next event. 37
There are the user interface elements that you see on screen, so those can be things such as buttons or
39
And when we first build our app we're going to set up the screen. 41
So we're going to drag on some buttons and place it in a location that we think makes sense and then 42
add images or add other interface elements to the screen. 43
Now when those elements get interacted with by the user say somebody taps on the button then we've
got 44
the second component of the app that comes into play which is the code and this code is the plan. 45
If this button called click me gets tapped on, then what's the next thing that should happen? 46
Well, it's step one do this. Step to do that. Step three do that. 47
But if the user, say, used the slider then in our code there'll be a section that plans for what should 48
And finally most of the apps especially if it gets more complex will have data that's stored in the 50
app. 51
So for example let's say we have a contact management app right where we have all the phone numbers
52
of all of your friends and colleagues. Well on the screen when the user taps on a button that says Show
53
Then that will send a message to our code and we check through all of those lines of code to see how 55
we should respond when the user taps on that button and the code will go into the data and fetch the 56
And then it's going to send it back onto the screen and display it on the screen so that the user now 59
Now previously I mentioned that a smartphone is just like a small computer but there's still a few crucial
61
differences. 62
The first difference is that a laptop or desktop computer is usually plugged into the wall but a phone 63
So if you tried to play something that's really intensive on your phone say the latest Far Cry or if 69
you try to run Photoshop on your phone then it's not going to be able to do it. 70
Because it has less memory and less processing power than your computer. 71
So because the phone has limited resources on all of these fronts then in order for a user to actually 72
have a good time using their iPhone, then we have to manage those resources very frugally. 73
So for example you can't just make an app that drains the user's power in five minutes or make an app 74
that's so demanding on processing power that it's so slow and barely chugs along on the phone. 75
So in all smartphones, there's always a manager -somebody to manage all of those resources. 76
So it's iOS in our case that we need to worry about. And this manager is a little bit like the factory 78
boss. 79
"Get ready." 81
"I'm going to have to shut you down" or "Hey you, little app, the user is getting a phone call right now" 84
And this is what I think about every time I see my apps shuddering and shaking in fear. 87
So previously we looked at the three components that make up any app namely the screen, the code, and
88
the data. 89
Well we actually have to zoom out a little bit and see the bigger picture which includes the role of 90
So when we think back to that plan that we're writing when we're coding up the apps, then that plan has
92
to take into account all of the events that happen not just when a button inside the app is tapped or 93
when the user shakes the phone when our app is open but also things such as when the operating
system 94
Well if the user is getting a phone call but they were midway through filling out a long form inside our 98
app, we don't want them to come back after the call and realize all of that data has been lost. 99
So we have to plan on how we save that data when a user gets a call for example. 100
So all in all when we build an app we're essentially writing a very long and very extensive plan to 101
plan for what should happen under lots of possible scenarios. 102
And when the app is launched on the phone it looks to this plan to see what it should do. 103
So, in the course we're going to be digging into every single aspect that we spoke about in this lesson
104
and this is a little bit of a teaser of what's yet to come and what you're going to be learning about. 105
So that by the end of the course you'll understand exactly how the app works and build any app that 106