[MUSIC] When you make a Core Data Project a few things are different, you get some code built for you and you get a couple of other interfaces that are available for building your project. So let's build a Core Data project that is going to, over a sequence of video lectures here, build up the example that we saw previously with the chore list. The first thing that you need to do is you need to create a new project as normal. And this time we're gonna specify that we want Core Data to be enabled when we build our project. So let's do that. Basically, the high level point of this is that core data projects are created slightly differently. No, it's not a huge difference, but just so you can see some of the things are different and I can walk you through that, and we're gonna do that. So, let's do it. Make a new project. It's gonna be a single view application. We'll call it coredatacoursera. And we'll give it an identifier there. And the main thing that we have to check is this one here, this use core data. Make sure that is checked, so that we get the additional tools that we need. We're going to click next, we're going to put it on our local workspace, and I'm going to maximize it for us. So the things that we see that are different, are a couple over here. We see that we get this core data model builder utility here. And this is where in my previous slides, I grabbed the screen shot of the chores, the chore list and the people model from. So, this is where you build it, here in this x data model ID. The other thing that's different, is in your app delegate file In addition to all this Bootstrap code that we get, we often just use finish launching with options. So I'll go ahead and delete these guys for clarity. Down below this compiler pragma mark, we see that Xcode has created that whole stack for us. It has created a managed object context, a managed object model, and a persistent store coordinator. There are several functions that are available for initializing this, and you can see as you walk through it that It's based on your project. You've got a persistent store coordinator. And when you ask for it, these are all functions that deliver the objects in question, the managed object context or the model or the persistent store coordinator. And you can see that if it hasn't been initialized it gets initialized in the appropriate way. Over here you can see a nod to the fact that there's a SQL Light database underneath the whole enterprise here. And then down here at the very bottom, you can see that there is a method that's there, that's available for saving all of the objects that are on the scratch pad in the managed object context. So up here at the top, what we're gonna do just in this little bit, is we are going to, after our application launches. We are going to add some code that's just going to manually initialize all of the different pieces of our core data stack. So let me just add that, oops, add that here. I'm gonna paste in the code here and the first thing that we do is we access our managed object model. So x code also created in the header file for the app delegate, variables for the managed object context, the managed object model, and the persistence store coordinator, and here's where it gave us access to our save function. Back here in our I get this. Our first function call is going to be to pass a message to ourself asking for the managed object model. Now this actually returns the managed object model, but we don't want to do anything with it. We just want to ask for it. Because in the process of asking for it, we initialize it. Now remember the managed object model was the lowest level of our core data stack, and it interacted with our model that we defined externally. At this point in our project, we haven't actually defined our model. So we're not gonna run this code. We're not gonna interact with our model yet. We're just gonna write it. The next thing that we're gonna do is, once our managed object model has been initialized by asking for it, we're gonna ask for the persistent store coordinator. That's going to connect with the managed object model, and it's going to fire up the SQLite files and fire up the database and connect those pieces together. And then the last thing that we're going to do is, we're going to ask for the managed object context. This is the piece that we're primarily going to be interacting with as developers. This is where we retrieve our managed objects from. And this is where we save them to. So we're going to go ahead and get a managed object context, managed object context, pointer. From that, we're gonna capture this one, and we're just gonna check to make sure it's not null. And we're gonna do that with an NS alert message, and we're gonna just make sure that everything went okay with the initialization. If it didn't go okay, our program will throw an alert, throw an assertion, at this point. So why might it not go? Well, you might not have enough space on your device. Something else might have gone wrong. But what this is going to do, is it's going to initialize those variables when our program first starts. That will give us access to them in the other pieces of our code. So let's go ahead in our view controller we haven't, we also haven't created an interface yet. In our view controller, let's just create a local variable that's going to give us access to our application. So that we can retrieve the managed object context from within our user interface. So let's go over to our view controller. And let's just say that when our view loads, we are going to ask the application for the one application object, which represents our app, and we're going to ask for the delegate. Which is our appDelegate.m, the object that's defined in our appDelegate.m file. And we are just going to keep a copy of that. Locally. And we're gonna do that, because we're gonna need access to our manage object context later. So let's create a property to hold it. And hopefully that will all work okay. And then we need to import our AppDelegate.h header file. And that work. All right, oh, sorry. We need to access self.appDelegate. Good. All right, and that is going to get us the ability to access our appDelegate and through the appDelegate, access our manage object context. All right. So that's how it's different to create a core data project. We haven't done much. We haven't created a user interface. We haven't created a model. That'll come next. But in summary, when we build our core data project, it comes with a model builder. That's the place where we're gonna build our model. It also comes with the template code that initializes that Core Data stack, all the way that connects the model and the SQLite database, all the way up to our managed object context. These are things that you could write manually. In fact, you used to have to, but now X code does it for you. So that's great. That makes it easier for us as developers. [MUSIC]