[MUSIC] In this video, what I want to do is add the components together to finalize this UI that we're working with. Since our last video, what I did is I cleaned up our user interface a little bit. I made it so it at least wasn't on top of each other. I added a date picker, which is a standard element that you can just drag and drop from the object library. And what I wanna do, is I wanna make is so that when we click this button here, we're going to take whatever is selected under chore, and whatever is selected under person, couple that with the current date, and make an entry in our chore log entity in our core data. I want to replace our label at the bottom, with a list of all of the chores that have been accomplished, and I want delete to delete everything we have in our entity, to start over. So let's go to our code and take a look at what we need to add. So the first thing that I wanna add is I want to add the ability to do something when our chore log entry is tapped. And what we're gonna do is we're going to do something very similar to what is happening in our other two, in the sense that we're gonna be creating a new element in our database. But how we do that is gonna be a little bit different. So chore log tapped, what I'm going to need to do is I'm going to need to pull out the row that's selected in our chore roller. So let's pull that out. Let's say our chore self.chore roller and selected row and component, column zero. It's the first column, that's all we've got. And we're going to set that equal to we'll call it the chore row. Make sure that clears okay. All right. Then we're just not doing anything with it so we get a warning. And then we're also going to collect person row from the person roller. Then we need to actually get the chore managed object and the person managed object associated with that. Now in our picker view helper, that's exactly what we're keeping track of. We're keeping track of all those managed objects for us. So we're gonna go ahead and go to self.choreRollerHelper. And we're going to getItemFromArray and we're gonna get item choreRow. And what we're gonna get back is gonna be a chore managed object. Then we're going to do the same thing, but we're going to get a person managed object from our person roller helper. Using our person route. All right. So the way that we decided, the way that we ended up making this, making our picker view helper work, is that it kept track of these managed objects for us, and so now when we select one we just go and ask the helper for those particular objects. Now we need to create a chore log entry. Managed object, and it is a pointer. And we're going to ask our app delegate to create a new chore log managed object. We will get that managed object back. And just like the other things we're going to set the chore log.personwhodidit=theperson. Now, notice here that we're actually setting an equal to another managed object. But in doing that, we're going to create a link between those two entities. And then we're going to set personchoredone. Chore done is gonna be equal to chore. And then, the last thing we need to do is set the attribute of this entity which is when. And that's gonna be equal to self. Oh, we haven't actually declared our date picker and our object yet so that we can use it. So let's come up here. And I'll do that. Do that. So now we have our date picker and we can say that chore log when equals self.datepicker.8. So now we have, we created a new managed object, our chore log entry, we set the different aspects of it. Our relationship was set to a different managed object, any relationships were set to managed objects, that we're able to get from our picker view helper. Our when was set from the date in our date picker. And so the last thing that we have to do in this particular method, is we need to save all that. All these, that new chore log element is in our scratch pad in our manage object context. And we need to say, okay manage object context, I've set all the fields, I'm ready for you to persist it. So now persist it. We do that, and we don't have any rollers to update. But what we are gonna do is we're gonna change what gets put in the label down here. So that's the next thing that we have to tackle. All right, we're getting some warnings here. What are our warnings? Incompatible pointer types initializing, oh, we just need to cast these items, To the appropriate type, because we declared them as containing something of type NSobject, and we are actually going to, we know that what we put in there was something more specific. NSobject is super type, and chromeManageObject, that's fine. Chore managed objects and person managed objects are children of that super type. Okay we go back to our initial view load, unload that we go through and we get, we set our initial app delegates, so we can get access to our app delegate dot m. We initialize our choreRollerHelper and our personRollerHelper to actually have objects. We connect our choreRoller to our choreRollerHelper. We connect our personRoller to our personRollerHelper. We update our choreRoller by loading it with the data from our persistent storage. We update our personRoller to load it with data from our persistent storage. And then we do this update log list, and right now update log list is coming from our chore list, and we don't want that, we want our update log list now to be coming from our chore log. So now, when we fetch, we'll get a bunch of chore log objects back. And we need to create the data that we're going to put down there. So we'll just do the same thing where we go through and we create a string based on the description, what our description function returns from chore log managed object, MO. If we don't override that description method, we're going to get back a bunch of hexadecimal characters, talking about the address of where that object is. So let's override that object, give us something helpful. So when each chore log managed object should output some summary of what's inside it. So let's go over here. What I'm gonna do is I'm gonna grab our description code from our Person managed object, put it in our Chore managed object. And we are going to construct a new string from a format. Let's see, what I would like to do is I would like to have something that is like the person in parentheses and the chore in parenthesis maybe and the time in parenthesis. And for that we're gonna need self, see self.chore done. Dot, chore done. .chore_name, because that's an object itself. And then we're gonna need self.person_who_did_it.person_name, and then we're gonna need self.when. Looks good to me. And we're going to just return that one object. Okay, then we will declare this publicly so that we override it. We're gonna override the method that we would otherwise inherit, and now we're gonna go back to our view controller. So now, when we initialize our view controller, we're gonna come down here and we're gonna update our log list. And our log list is gonna be updated with our chore log entries instead of our chores. The other time when we wanna update this is after we add a new chore log entry. So if we had a new chore log entry, we also wanna update that list. All right. Finally, when delete is tapped we wanna go through and delete all of our data. So if we tap delete right now, we're just deleting our chore managed objects. So we're gonna go through and we're just gonna do this three times. We'll do this. Actually, I wonder. Let's see if we can pull this out using our refactoring. So Edit and. Where's my Refactor? Refactor > Extract. And let's, oh, don't crash on me. Okay, we were working on refactoring our delete tapped button. I tried to use X code's refactoring capabilities. It crashed. So we're just not going to do anything fancy. What we're going to do is we're just going to repeat this code, instead of deleting chore, we're going to delete the person element and then the person log. So we'll re-use that variable. Instead we'll go through person. Error fetching our chore objects. Go through person, error fetching person objects, as we go through our results, they're now person MOs. We're gonna delete those objects. We're going to reuse our error variable. We're going to reuse our results variable. And we'll go through and we will do the same thing. Need copying up there, try again. We'll go through and we'll do the same thing with our chore log. And if we have an error it's because of our chore log objects. Put our chore log in our results and what we're going to delete as I'll mention in our chore log. Now, when we delete these things they're just being deleted in our managed object context. So to persist that change into our SQLite database, we need to actually save our context. And we're gonna have to call break. All right, and then we'll update our log list to reflect the fact that everything's deleted. All right, so this is it. This is the final run. What I discovered was that I was having a problem because my buttons were actually calling multiple functions every time I clicked them. And the way I figured that out is I came over here and I would select a button and I would right click over here and I would see that multiple, there were multiple entries under touch up inside. So what I did is I deleted them all, I deleted them all by clicking on an x that was present before and now I'm going to reestablish the code that runs when those buttons are hit. So I'm going to connect chore tapped to add chore. I'm gonna connect person tapped to add person. I'm gonna connect chore log tapped to add chore log. And I'm going to connect delete tapped to delete. Now when I select say add person and I right-click, you can see that there's one function listed there and that's the function that I want called. Okay, so now when I run it, I have break points. Let's disable the break points. Keep running it. Now we're gonna add a chore like washing the dog and we add a person like mom and add another person like dad and I can say washing the dog by dad. Today at 5:13 I'm gonna add a chore log entry, I have a break point there we're always debugging, gonna disable that and run. And you can see that, finally, we made a chore log entry which was add chore log entry washing the dog dad. We can add another one, which is washing the dishes, add that. Now we set washing the dishes and mom. One minute in the future. Add a chore log entry and we get that. Great. Now when we double hit the home button and we knock it out of memory and we rerun the application, all those entries are still present. And all of our data has persisted. Both our data about the chores, our data about the people and the chore list itself. Finally when I hit the delete button, they'll all be wiped away. They'll all be wiped away but I didn't update the chore roller. So let's do that as a final step. We updated the log list, but we also need to do self updateChoreRoller, and self updatePersonRoller. Try again. All right, so let's add the chores, make sure this works. Washing the dishes, add the chore. Person, Mom. Washing the car. Person, Dad. Say, Mom washed the car today. And then Dad washed the dishes. Looks good. Let's clear that out of memory. Let's run it again. That information still persists. We can add another chore log entry. And when we hit delete, everything should go away. If we swipe it out of memory then, and we restart, none of that information is there because we've deleted it all. Okay. So that took long a time. Got all the pieces together and this is a lot more than you're gonna need to do for your final peer review assignment. But if you wanted to do it all, that's kind of the steps that you have to go through, and you can see that there's some debugging that has to happen, even when you know what you're doing. You make mistakes in the rush of trying to get stuff done. Okay, thank you for your attention. [MUSIC]