Now, before we talk about and NSCoder and how we can start saving our custom objects to file, 1
we first have to understand a concept known as sandboxing. 2
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
I have some malicious software. And I try to infect the other apps on the same phone and maybe 4
my code's intention is to mess up the other apps, or maybe I'm trying to get secure data from the other 5
apps. 6
And if you're weather apps start stealing data from your banking apps on the same phone, then you have 7
a huge problem. 8
And so in iOS, this problem is solved by something known as sandboxing. 9
So imagine that all of your apps on your phone live inside their own sandboxes. And a sandbox is nothing 10
more than just a sheltered environment, 11
or maybe you can consider it as a little mini prison for your app. 12
So each of the apps has their own folders to store files and documents that are associated with the 13
app. 14
And so when your to do list app needs to save or retrieve data, it can do so by reading and writing to 15
that Documents folder, but it can't get access to another apps document folder. 16
Instead, what happens is that every time your phone syncs with iCloud or when you plug it into your laptop 17
and you sync it with iTunes, then all of these document folders gets backed up, either online or locally 18
to your laptop. 19
So, say, if you go out and buy a brand-new phone, any data that your app has saved to that Documents folder 20
doesn't get deleted. 21
Instead, it will constantly sync with iCloud or with iTunes 22
and it will remain available for you to be able to read and write to it and grab the data that's been 23
stored in it throughout the lifetime of the app. 24
So in other words, because you have this backed up permanent storage solution, it doesn't matter if you 25
change phones, if you update your operating system, 26
if you download new versions of the app, you still have your personal data safely stored somewhere where 27
the app can get access to. 28
Now, sandboxing doesn't just apply to individual apps. 29
It also means that apps themselves can affect the operating system's code. 30
So you can't write a malicious app to grab the secure data from the operating system. 31
For example, the user's fingerprints or their contacts. 32
And this is also one of the reasons why the iPhone is considered to be far safer and more secure when 33
compared to other phones and other operating systems. 34
But it also means that, sadly, you can't make cool apps that changes the operating system settings. 35
So, for example, one of the apps that I really wanted to make is an app where when I turn my phone to 36
be face down onto the table, i.e., when the proximity sensors detect that it's occluded, then I want my 37
app to automatically switch my phone into to "Do not disturb" mode because it usually means that I'm either 38
having a conversation or I'm having dinner or I'm trying to work on something, and that would be really 39
awesome. 40
But without jailbreaking the iPhone, which is really not recommended, 41
there's no way of implementing this on iOS. 42
So there's benefits to sandboxing and there's also a cost to sandboxing. 43
But this is something that we have to work with as an iOS developer. And in the next lesson, I'm going 44
to show you how to get access to your Documents folder inside your apps and how to start saving your 45
custom objects to that directory. 46
So for all of that and more on the next lesson.