0 1 00:00:00,550 --> 00:00:04,710 So in the last episode, I promise you that we're going to be able to view our data. 1 2 00:00:04,840 --> 00:00:09,620 But at the moment, we don't have the code set up yet so that we can see it in our table view. 2 3 00:00:09,880 --> 00:00:11,590 So how can we do this? 3 4 00:00:11,680 --> 00:00:19,630 Well, we first need to locate our file. And even though we don't need this data file path anymore because 4 5 00:00:19,630 --> 00:00:26,160 we're not using it to save our plist, we can still cut it, put it into our viewDidLoad, 5 6 00:00:26,200 --> 00:00:31,660 and we're going to print the file path for our documentDirectory under the userDomainMask. 6 7 00:00:31,690 --> 00:00:37,600 But without all the appending in the first and all of that, we just want to get a path to where the data 7 8 00:00:37,600 --> 00:00:40,460 is being stored for our current app. 8 9 00:00:40,480 --> 00:00:46,380 So if we run our app right now, we'll see that file path pop up in our debug console. 9 10 00:00:46,420 --> 00:00:50,240 So let's follow the clues. We're going into User, 10 11 00:00:50,500 --> 00:00:59,190 angelayu, Library, Developer. Instead of Xcode which is where we found our automatically generated code, 11 12 00:00:59,290 --> 00:01:01,730 instead, we're going to go into our CoreSimulator, 12 13 00:01:02,230 --> 00:01:09,490 and then we're going to go to Devices, and our current simulator is 8D49, something, something, something. 13 14 00:01:09,850 --> 00:01:17,720 We're going to go into Data, Containers., Data, and then we're going to go into Application, and the Application 14 15 00:01:17,730 --> 00:01:21,990 for our current Todoey app is 5BF, something, something, something. 15 16 00:01:22,210 --> 00:01:28,840 Now, inside here, instead of going into Library, Preferences, where we'll find our plist, instead we're 16 17 00:01:28,840 --> 00:01:33,200 going to go into Library and Application Support. 17 18 00:01:33,250 --> 00:01:37,820 Here is where you're going to find your DataModel.sqlite file 18 19 00:01:37,870 --> 00:01:39,860 and this contains our database. 19 20 00:01:39,880 --> 00:01:44,830 So whereas I've got this little icon that shows me that I've got an application that's able to open 20 21 00:01:44,830 --> 00:01:48,060 this file, you might just see something like this, 21 22 00:01:48,100 --> 00:01:51,630 which means that your operating system doesn't know how to open the file. 22 23 00:01:51,760 --> 00:01:56,350 And we can solve this easily by going to the App Store and we're going to search for SQLite., 23 24 00:01:56,350 --> 00:01:58,530 so it's S-Q-L-I-T-E. 24 25 00:01:58,570 --> 00:02:05,230 And here, you can see a whole bunch of different applications that can help you manipulate, add, delete, 25 26 00:02:05,950 --> 00:02:08,320 or view your SQLite databases. 26 27 00:02:08,480 --> 00:02:15,190 And one that I quite like is Datum, and they've even got a free version which will be more than enough 27 28 00:02:15,310 --> 00:02:18,530 for our purposes in order to view our Core Data. 28 29 00:02:18,700 --> 00:02:23,980 So just go ahead and download and install Datum Free and you can follow along with me in the next steps 29 30 00:02:24,280 --> 00:02:26,020 to view our Core Data. 30 31 00:02:26,020 --> 00:02:27,760 Now, this is not the only option, 31 32 00:02:27,760 --> 00:02:32,590 there's a whole bunch of other applications. And you might already even have an app that allows you to 32 33 00:02:32,590 --> 00:02:34,680 manipulate SQLite databases. 33 34 00:02:34,840 --> 00:02:37,590 If you have a preference, then just go with whatever you like. 34 35 00:02:37,600 --> 00:02:42,460 We're using it for the most basic functionality. But if you never use an application to open SQLite 35 36 00:02:42,520 --> 00:02:47,830 databases or you've never even heard of what SQLite is, then just go with the free option. 36 37 00:02:47,830 --> 00:02:53,310 So once we've got that application installed, we can simply double click on our DataModel.SQLite, 37 38 00:02:53,830 --> 00:02:57,060 and I'm going to use Datum Free to show you how it works. 38 39 00:02:57,070 --> 00:02:59,210 So you might see some of these pop-ups "Upgrade Now!" 39 40 00:02:59,220 --> 00:03:02,530 Not now. We're going to try it for a little while 40 41 00:03:02,770 --> 00:03:04,620 while I show you how this works. 41 42 00:03:05,110 --> 00:03:10,800 And inside here, we've got this table called ZITEM. 42 43 00:03:10,840 --> 00:03:15,300 And her, if you scroll through the right, you'll see one attribute called ZDONE 43 44 00:03:15,310 --> 00:03:16,960 And one called ZTITLE. 44 45 00:03:16,960 --> 00:03:22,840 So if you ignore those "Zs," you can see that these are the names of our attributes. And done is set to 0 45 46 00:03:22,840 --> 00:03:29,660 which is false, and title is set to "Save the World!" which is what we added just now into our app, 46 47 00:03:29,860 --> 00:03:33,660 even though we're unable to load it up if we terminate our app. 47 48 00:03:33,730 --> 00:03:40,540 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 49 00:03:40,570 --> 00:03:49,030 "Buy Eggos," and hit Add Item, then you see it showing up in the table view because it's being loaded up from 49 50 00:03:49,030 --> 00:03:49,720 the array. 50 51 00:03:49,870 --> 00:03:57,010 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 52 00:03:57,070 --> 00:04:01,900 also being saved and persisted in our SQLite database. 52 53 00:04:01,900 --> 00:04:09,670 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 54 00:04:09,670 --> 00:04:16,470 managed objects into the Core Data data model, and how we can view it using a SQLite applications 54 55 00:04:16,470 --> 00:04:19,160 such as data. In the next lesson, 55 56 00:04:19,180 --> 00:04:23,800 we're going to review some of those concepts that we've come across so far, and we're going to talk about 56 57 00:04:23,800 --> 00:04:29,620 some of these tricky things like persistentContainers and viewContext, and we're going to learn some 57 58 00:04:29,620 --> 00:04:31,960 of the fundamentals of Core Data. 58 59 00:04:31,990 --> 00:04:34,960 So for all of that and more, I'll see you on the next lesson.