So in the last episode, I promise you that we're going to be able to view our data. 1
But at the moment, we don't have the code set up yet so that we can see it in our table view. 2
So how can we do this? 3
Well, we first need to locate our file. And even though we don't need this data file path anymore because 4
we're not using it to save our plist, we can still cut it, put it into our viewDidLoad, 5
and we're going to print the file path for our documentDirectory under the userDomainMask. 6
But without all the appending in the first and all of that, we just want to get a path to where the data 7
is being stored for our current app. 8
So if we run our app right now, we'll see that file path pop up in our debug console. 9
So let's follow the clues. We're going into User, 10
angelayu, Library, Developer. Instead of Xcode which is where we found our automatically generated code, 11
instead, we're going to go into our CoreSimulator, 12
and then we're going to go to Devices, and our current simulator is 8D49, something, something, something. 13
We're going to go into Data, Containers., Data, and then we're going to go into Application, and the Application 14
for our current Todoey app is 5BF, something, something, something. 15
Now, inside here, instead of going into Library, Preferences, where we'll find our plist, instead we're 16
going to go into Library and Application Support. 17
Here is where you're going to find your DataModel.sqlite file 18
and this contains our database. 19
So whereas I've got this little icon that shows me that I've got an application that's able to open 20
this file, you might just see something like this, 21
which means that your operating system doesn't know how to open the file. 22
And we can solve this easily by going to the App Store and we're going to search for SQLite., 23
so it's S-Q-L-I-T-E. 24
And here, you can see a whole bunch of different applications that can help you manipulate, add, delete, 25
or view your SQLite databases. 26
And one that I quite like is Datum, and they've even got a free version which will be more than enough 27
for our purposes in order to view our Core Data. 28
So just go ahead and download and install Datum Free and you can follow along with me in the next steps 29
to view our Core Data. 30
Now, this is not the only option, 31
there's a whole bunch of other applications. And you might already even have an app that allows you to 32
manipulate SQLite databases. 33
If you have a preference, then just go with whatever you like. 34
We're using it for the most basic functionality. But if you never use an application to open SQLite 35
databases or you've never even heard of what SQLite is, then just go with the free option. 36
So once we've got that application installed, we can simply double click on our DataModel.SQLite, 37
and I'm going to use Datum Free to show you how it works. 38
So you might see some of these pop-ups "Upgrade Now!" 39
Not now. We're going to try it for a little while 40
while I show you how this works. 41
And inside here, we've got this table called ZITEM. 42
And her, if you scroll through the right, you'll see one attribute called ZDONE 43
And one called ZTITLE. 44
So if you ignore those "Zs," you can see that these are the names of our attributes. And done is set to 0 45
which is false, and title is set to "Save the World!" which is what we added just now into our app, 46
even though we're unable to load it up if we terminate our app. 47
But you can see that the data is, in fact, being persisted. And right now, if I add a new item, let's say, 48
"Buy Eggos," and hit Add Item, then you see it showing up in the table view because it's being loaded up from 49
the array. 50
But if we have a look over here to our item table and we refresh our data, then you can see that it's 51
also being saved and persisted in our SQLite database. 52
So up till now, we've seen how we can create a new Core Data data model, how we can save new items on new 53
managed objects into the Core Data data model, and how we can view it using a SQLite applications 54
such as data. In the next lesson, 55
we're going to review some of those concepts that we've come across so far, and we're going to talk about 56
some of these tricky things like persistentContainers and viewContext, and we're going to learn some 57
of the fundamentals of Core Data. 58
So for all of that and more, I'll see you on the next lesson.