0 1 00:00:00,420 --> 00:00:05,470 Now, before we talk about and NSCoder and how we can start saving our custom objects to file, 1 2 00:00:05,490 --> 00:00:08,700 we first have to understand a concept known as sandboxing. 2 3 00:00:08,700 --> 00:00:15,540 Now, here's a scenario. Say, if I have two apps which are running on the same phone and one of my apps, say, inside Clima, 3 4 00:00:15,540 --> 00:00:24,330 I have some malicious software. And I try to infect the other apps on the same phone and maybe 4 5 00:00:24,330 --> 00:00:30,240 my code's intention is to mess up the other apps, or maybe I'm trying to get secure data from the other 5 6 00:00:30,240 --> 00:00:30,750 apps. 6 7 00:00:30,900 --> 00:00:36,510 And if you're weather apps start stealing data from your banking apps on the same phone, then you have 7 8 00:00:36,510 --> 00:00:38,210 a huge problem. 8 9 00:00:38,250 --> 00:00:43,170 And so in iOS, this problem is solved by something known as sandboxing. 9 10 00:00:43,380 --> 00:00:51,390 So imagine that all of your apps on your phone live inside their own sandboxes. And a sandbox is nothing 10 11 00:00:51,390 --> 00:00:53,500 more than just a sheltered environment, 11 12 00:00:53,730 --> 00:00:57,520 or maybe you can consider it as a little mini prison for your app. 12 13 00:00:57,540 --> 00:01:03,720 So each of the apps has their own folders to store files and documents that are associated with the 13 14 00:01:03,720 --> 00:01:04,390 app. 14 15 00:01:04,410 --> 00:01:10,820 And so when your to do list app needs to save or retrieve data, it can do so by reading and writing to 15 16 00:01:10,850 --> 00:01:16,410 that Documents folder, but it can't get access to another apps document folder. 16 17 00:01:16,410 --> 00:01:22,440 Instead, what happens is that every time your phone syncs with iCloud or when you plug it into your laptop 17 18 00:01:22,470 --> 00:01:29,220 and you sync it with iTunes, then all of these document folders gets backed up, either online or locally 18 19 00:01:29,220 --> 00:01:30,420 to your laptop. 19 20 00:01:30,420 --> 00:01:37,290 So, say, if you go out and buy a brand-new phone, any data that your app has saved to that Documents folder 20 21 00:01:37,650 --> 00:01:39,180 doesn't get deleted. 21 22 00:01:39,180 --> 00:01:43,310 Instead, it will constantly sync with iCloud or with iTunes 22 23 00:01:43,590 --> 00:01:49,140 and it will remain available for you to be able to read and write to it and grab the data that's been 23 24 00:01:49,140 --> 00:01:52,410 stored in it throughout the lifetime of the app. 24 25 00:01:52,410 --> 00:01:58,320 So in other words, because you have this backed up permanent storage solution, it doesn't matter if you 25 26 00:01:58,320 --> 00:02:01,490 change phones, if you update your operating system, 26 27 00:02:01,560 --> 00:02:08,070 if you download new versions of the app, you still have your personal data safely stored somewhere where 27 28 00:02:08,070 --> 00:02:10,060 the app can get access to. 28 29 00:02:10,110 --> 00:02:13,810 Now, sandboxing doesn't just apply to individual apps. 29 30 00:02:13,860 --> 00:02:19,550 It also means that apps themselves can affect the operating system's code. 30 31 00:02:19,650 --> 00:02:25,010 So you can't write a malicious app to grab the secure data from the operating system. 31 32 00:02:25,050 --> 00:02:28,400 For example, the user's fingerprints or their contacts. 32 33 00:02:28,560 --> 00:02:35,190 And this is also one of the reasons why the iPhone is considered to be far safer and more secure when 33 34 00:02:35,190 --> 00:02:38,260 compared to other phones and other operating systems. 34 35 00:02:38,340 --> 00:02:44,060 But it also means that, sadly, you can't make cool apps that changes the operating system settings. 35 36 00:02:44,070 --> 00:02:50,400 So, for example, one of the apps that I really wanted to make is an app where when I turn my phone to 36 37 00:02:50,400 --> 00:02:58,110 be face down onto the table, i.e., when the proximity sensors detect that it's occluded, then I want my 37 38 00:02:58,200 --> 00:03:04,200 app to automatically switch my phone into to "Do not disturb" mode because it usually means that I'm either 38 39 00:03:04,200 --> 00:03:10,230 having a conversation or I'm having dinner or I'm trying to work on something, and that would be really 39 40 00:03:10,290 --> 00:03:10,980 awesome. 40 41 00:03:11,130 --> 00:03:15,450 But without jailbreaking the iPhone, which is really not recommended, 41 42 00:03:15,570 --> 00:03:19,040 there's no way of implementing this on iOS. 42 43 00:03:19,110 --> 00:03:23,020 So there's benefits to sandboxing and there's also a cost to sandboxing. 43 44 00:03:23,190 --> 00:03:28,320 But this is something that we have to work with as an iOS developer. And in the next lesson, I'm going 44 45 00:03:28,320 --> 00:03:35,640 to show you how to get access to your Documents folder inside your apps and how to start saving your 45 46 00:03:35,640 --> 00:03:38,270 custom objects to that directory. 46 47 00:03:38,640 --> 00:03:41,280 So for all of that and more on the next lesson.