0 1 00:00:00,360 --> 00:00:00,890 Hi guys. 1 2 00:00:00,900 --> 00:00:02,910 This is Angela from the app brewery. 2 3 00:00:02,910 --> 00:00:09,060 And before we get started digging in and building apps the first thing I want to talk about is how exactly 3 4 00:00:09,090 --> 00:00:10,370 does an app work. 4 5 00:00:10,410 --> 00:00:16,470 Because we'll have it in our phones we use it to do really important things like banking and contacting 5 6 00:00:16,470 --> 00:00:17,040 friends. 6 7 00:00:17,130 --> 00:00:22,290 But there are actually very few people who know just exactly how an app actually works. 7 8 00:00:22,290 --> 00:00:24,950 So let's start off by getting an overview of that. 8 9 00:00:25,320 --> 00:00:31,290 Now the first thing we have to realize is that smartphones are actually no different from just any other 9 10 00:00:31,290 --> 00:00:38,430 computer and an app is just code that we write to tell that mini computer what it should do. 10 11 00:00:38,490 --> 00:00:43,860 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 12 00:00:43,890 --> 00:00:45,840 on the screen of that phone. 12 13 00:00:45,870 --> 00:00:52,710 Then the sensors in the phone register that tap and sends a message to the operating system which in 13 14 00:00:52,710 --> 00:00:55,150 the case of an iPhone would be iOS. 14 15 00:00:55,170 --> 00:01:00,330 Now the operating system then looks at the data that it gets from the sensor including things such as 15 16 00:01:00,330 --> 00:01:07,740 how much pressure was applied onto the phone at which location on the phone screen did it register that 16 17 00:01:07,740 --> 00:01:11,840 pressure and a whole bunch of different things and a whole lot of numbers. 17 18 00:01:11,940 --> 00:01:16,710 But the operating system takes all of those numbers and makes sense of it. 18 19 00:01:16,710 --> 00:01:22,410 And once it does then it will know that this particular button on the screen of this particular app 19 20 00:01:22,680 --> 00:01:29,760 was tapped at this time point and then he'll send a message to the app in question telling it that hey 20 21 00:01:30,270 --> 00:01:32,690 this button of yours got tapped. 21 22 00:01:32,850 --> 00:01:34,610 What should it do? 22 23 00:01:34,620 --> 00:01:41,400 And so the code that you write for your app should specify in this situation when the button called 23 24 00:01:41,400 --> 00:01:42,750 Click me gets tapped, 24 25 00:01:42,780 --> 00:01:44,840 this is what it should do. 25 26 00:01:44,880 --> 00:01:46,940 It should change what's shown on screen. 26 27 00:01:47,070 --> 00:01:48,940 And it should do this and that and that. 27 28 00:01:49,110 --> 00:01:55,340 So essentially as an app developer you're planning out all of the scenarios and what should happen. 28 29 00:01:55,410 --> 00:02:01,570 In each case was almost a bit like emergency planning if the building is on fire. 29 30 00:02:01,680 --> 00:02:03,300 What should happen. 30 31 00:02:03,300 --> 00:02:08,550 Well we should probably evacuate the staff and we should probably shut all the doors to prevent the 31 32 00:02:08,550 --> 00:02:10,140 fire from spreading. 32 33 00:02:10,140 --> 00:02:12,800 Well it's exactly the same for apps. 33 34 00:02:12,870 --> 00:02:16,440 What should happen when a user taps on this particular button? 34 35 00:02:16,650 --> 00:02:19,750 Well we should change the screen background to red. 35 36 00:02:19,800 --> 00:02:25,350 We should show them some other pieces of information and then we'll wait to see what the user does next. 36 37 00:02:25,350 --> 00:02:28,770 And then there's a plan for how to respond to the next event. 37 38 00:02:29,040 --> 00:02:34,020 So this essentially only three components to every single mobile app. 38 39 00:02:34,080 --> 00:02:40,380 There are the user interface elements that you see on screen, so those can be things such as buttons or 39 40 00:02:40,680 --> 00:02:44,390 images or toggles and sliders. 40 41 00:02:44,430 --> 00:02:47,670 And when we first build our app we're going to set up the screen. 41 42 00:02:47,670 --> 00:02:52,920 So we're going to drag on some buttons and place it in a location that we think makes sense and then 42 43 00:02:53,010 --> 00:02:57,390 add images or add other interface elements to the screen. 43 44 00:02:57,390 --> 00:03:03,990 Now when those elements get interacted with by the user say somebody taps on the button then we've got 44 45 00:03:03,990 --> 00:03:10,170 the second component of the app that comes into play which is the code and this code is the plan. 45 46 00:03:10,170 --> 00:03:15,660 If this button called click me gets tapped on, then what's the next thing that should happen? 46 47 00:03:15,660 --> 00:03:19,550 Well, it's step one do this. Step to do that. Step three do that. 47 48 00:03:19,710 --> 00:03:26,310 But if the user, say, used the slider then in our code there'll be a section that plans for what should 48 49 00:03:26,310 --> 00:03:28,900 happen when the user uses the slider. 49 50 00:03:29,310 --> 00:03:36,120 And finally most of the apps especially if it gets more complex will have data that's stored in the 50 51 00:03:36,120 --> 00:03:36,570 app. 51 52 00:03:36,570 --> 00:03:42,960 So for example let's say we have a contact management app right where we have all the phone numbers 52 53 00:03:42,960 --> 00:03:48,870 of all of your friends and colleagues. Well on the screen when the user taps on a button that says Show 53 54 00:03:48,870 --> 00:03:50,670 me Bob's phone number. 54 55 00:03:50,760 --> 00:03:57,540 Then that will send a message to our code and we check through all of those lines of code to see how 55 56 00:03:57,540 --> 00:04:03,930 we should respond when the user taps on that button and the code will go into the data and fetch the 56 57 00:04:03,930 --> 00:04:05,130 relevant piece of data. 57 58 00:04:05,460 --> 00:04:08,160 So in this case that's of course Bob's phone number. 58 59 00:04:08,400 --> 00:04:14,700 And then it's going to send it back onto the screen and display it on the screen so that the user now 59 60 00:04:14,700 --> 00:04:17,270 sees the telephone number of Bob. 60 61 00:04:17,280 --> 00:04:25,140 Now previously I mentioned that a smartphone is just like a small computer but there's still a few crucial 61 62 00:04:25,140 --> 00:04:26,290 differences. 62 63 00:04:26,310 --> 00:04:33,450 The first difference is that a laptop or desktop computer is usually plugged into the wall but a phone 63 64 00:04:33,450 --> 00:04:35,880 on the other hand is usually wireless. 64 65 00:04:35,880 --> 00:04:39,910 We usually keep it in our pocket and it's not always charging. 65 66 00:04:39,930 --> 00:04:41,570 It's also a lot smaller. 66 67 00:04:41,600 --> 00:04:46,480 So the battery gets depleted much faster compared to a laptop. 67 68 00:04:46,590 --> 00:04:50,560 Now a phone also has less processing power. 68 69 00:04:50,610 --> 00:04:55,860 So if you tried to play something that's really intensive on your phone say the latest Far Cry or if 69 70 00:04:55,860 --> 00:04:59,630 you try to run Photoshop on your phone then it's not going to be able to do it. 70 71 00:04:59,810 --> 00:05:03,710 Because it has less memory and less processing power than your computer. 71 72 00:05:03,950 --> 00:05:10,520 So because the phone has limited resources on all of these fronts then in order for a user to actually 72 73 00:05:10,520 --> 00:05:16,920 have a good time using their iPhone, then we have to manage those resources very frugally. 73 74 00:05:16,940 --> 00:05:23,630 So for example you can't just make an app that drains the user's power in five minutes or make an app 74 75 00:05:23,660 --> 00:05:30,350 that's so demanding on processing power that it's so slow and barely chugs along on the phone. 75 76 00:05:30,350 --> 00:05:37,630 So in all smartphones, there's always a manager -somebody to manage all of those resources. 76 77 00:05:37,880 --> 00:05:40,450 And that is of course the operating system. 77 78 00:05:40,700 --> 00:05:46,130 So it's iOS in our case that we need to worry about. And this manager is a little bit like the factory 78 79 00:05:46,130 --> 00:05:46,590 boss. 79 80 00:05:46,610 --> 00:05:49,300 It tells our app "Hey, you're about to come on screen now." 80 81 00:05:49,310 --> 00:05:49,940 "Get ready." 81 82 00:05:49,940 --> 00:05:51,860 "The user wants to see something from you." 82 83 00:05:51,890 --> 00:05:56,170 "Don't let me down". Or it might say "Hey! You're draining the battery way too much." 83 84 00:05:56,180 --> 00:06:00,630 "I'm going to have to shut you down" or "Hey you, little app, the user is getting a phone call right now" 84 85 00:06:00,630 --> 00:06:02,160 "and I'm going to have to switch you off." 85 86 00:06:02,210 --> 00:06:04,590 "Make sure you save their data before you go home." 86 87 00:06:04,640 --> 00:06:09,200 And this is what I think about every time I see my apps shuddering and shaking in fear. 87 88 00:06:09,200 --> 00:06:15,110 So previously we looked at the three components that make up any app namely the screen, the code, and 88 89 00:06:15,110 --> 00:06:16,100 the data. 89 90 00:06:16,100 --> 00:06:20,840 Well we actually have to zoom out a little bit and see the bigger picture which includes the role of 90 91 00:06:20,840 --> 00:06:22,070 the operating system. 91 92 00:06:22,100 --> 00:06:27,980 So when we think back to that plan that we're writing when we're coding up the apps, then that plan has 92 93 00:06:27,980 --> 00:06:34,010 to take into account all of the events that happen not just when a button inside the app is tapped or 93 94 00:06:34,010 --> 00:06:40,550 when the user shakes the phone when our app is open but also things such as when the operating system 94 95 00:06:40,550 --> 00:06:43,640 tells us that the user is getting a phone call. 95 96 00:06:43,670 --> 00:06:46,090 So our app is going to be switched into the background. 96 97 00:06:46,220 --> 00:06:49,460 So we have to also plan ahead for those situations. 97 98 00:06:49,730 --> 00:06:55,970 Well if the user is getting a phone call but they were midway through filling out a long form inside our 98 99 00:06:56,000 --> 00:07:01,660 app, we don't want them to come back after the call and realize all of that data has been lost. 99 100 00:07:01,670 --> 00:07:07,070 So we have to plan on how we save that data when a user gets a call for example. 100 101 00:07:07,100 --> 00:07:14,150 So all in all when we build an app we're essentially writing a very long and very extensive plan to 101 102 00:07:14,150 --> 00:07:18,310 plan for what should happen under lots of possible scenarios. 102 103 00:07:18,380 --> 00:07:24,200 And when the app is launched on the phone it looks to this plan to see what it should do. 103 104 00:07:24,590 --> 00:07:30,980 So, in the course we're going to be digging into every single aspect that we spoke about in this lesson 104 105 00:07:31,460 --> 00:07:37,130 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 106 00:07:37,220 --> 00:07:44,420 So that by the end of the course you'll understand exactly how the app works and build any app that 106 107 00:07:44,420 --> 00:07:45,140 you dream of.