So the next thing we need to work on here is how do we delete each of these items because we have them
now.
It's also important to be able to delete them.
So one thing I noticed with a swifty why Now these may change it later because we are still in beta
meaning it's not the full version yet they're still working on it.
Is that with delete deleting items from our list we can swipe left and see that delete button or just
go ahead and swipe left completely and then this item is gone.
For that to work we can't just go ahead and say that on delete like this it somehow doesn't show what.
OK it should work but it doesn't show up.
So I figure out that the way for this to work is that we need to create the actual for each loop inside
of a list meaning instead of having everything like this and then I just do like that we have to create
a list.
It's going to be just an empty one and then I'm going to say before each side like this I'm going to
go ahead and say just like what we did before.
Here's in fact that can just go ahead and copy this and pass there and do what we did before say item
in and then I'm gonna go ahead and say no do row.
And when I pass the you know do such for No do I'm going to say item and then.
And for that I'm not gonna pass anything into go I mean I say Self that time ago I said.
OK.
Only when you do that are you going to be able to come inside here and say dot on delete.
Will that work.
OK then I'm going to pass in a function here to delete and when I just say delete which we haven't created
yet.
OK there we go.
It's called us delete item one thing is the best.
So what I'm gonna to do at the bottom here I'm going to say func called delete item of sets and they're
gonna be of index set type.
So what is this index set type.
Here is a collection of unique integer values that represent the indexes indexes of elements in another
collection.
So all of the collections that we are gonna pass through in this case just one collection which is our
list of items here.
It's going to be mapped with indexes.
So that's what we're doing here.
So the return type is going to be nothing because we don't wanna return anything anybody is going to
be something like this.
Now in this case here we want to convert these indexes into an array and get the index to where we want
to get because there seems to be a bug that prevents us from using these offsets straight to get the
index for each item.
Because remember when we perform delete we want to be able to pass the index of each item that we want
to delete because we don't want to just pass an arbitrary index and end up deleting something that it's
not what we want to delete because everything instead of array which means each item instead of array
has an index number.
So we need to have that index number in order for us to delete the correct one.
So that is why we're passing this this index set here contains a lot of things but we need to kind of
parse the win Get what we want because of the bug.
So we need to convert to index whatever we get from our index sets.
So I'm gonna go ahead and say guard because we don't know if this is going to work and why.
So guard ourselves if you will let index be equal to.
I'm going to put everything inside of an array object.
So in this case I'm just converting everything into an array which what is the thing is the offsets
that we're passing these offsets there and then I'm gonna just go ahead and get the first item that
I can find in that array.
So it's gonna be just the item inside or the first item there and then say else I'm gonna just go ahead
and return something.
Nothing there.
OK.
So if something works if some doesn't work out as we intended we're just going to get it we're just
going to leave this as it is and call it good.
So now that we have our index in fact that can go ahead and say print in this case here I'm going to
say removed a little interpolation here when say self dot no do list and then because it's NRA it can
pass and index of which index the index that we just created there.
OK so now if you call this method which is being actually called When we delete item we should be for
now we gonna be able to see something hopefully if all goes well.
So let's save this and run.
Let's go ahead and add something and if we the moment you do like this.
Look at that.
Now you have that capability because we've attached its own delete to our list but it has to be this
way because as I show you the way we had to before it wasn't allowing us to attach to own delete and
just like that we can go like this in the moment you should delete it says removed the item added.
Now it's still there which is OK because we actually like removing the item completely yet at this point
here we're just showing the item inside.
We're not removing anything that's why it's not going away even though it says removed it's not removing
it.
It's not until we come down here and say self that you no do list and then I'm going vote with the remove
method of any array that should have and then I'm going to remove at a certain index what index is going
to be the index that we just created at this point here we actually going to remove the item from the
list which means then the view will have to rebuild itself and remove that row row one enter.
Look at this.
If I just go like this and delete and now it's totally gone OK I can go ahead and add something else
something else something else.
So now I have all this functionality click here.
It's done.
I can still remove it.
Done back can remove it or just click delete and it's gone.
Why.
Because we actually now removing from our do list and because no do list remember is in is bound to
our view it knows exactly if something changes here it's going to go ahead and change the view as well.
That's why we're able to not even see it there.
It just removes itself
all right.
Here we go.
And just like that we were able to put together a very nice working application.
No do list.
Now there's one more thing that we want to do here.
Or two I should say it would be really nice if every time that we actually enter something we hit enter
like this.
We want to clear our text field just to get rid of everything nice inside there.
Right.
That'll be really nice.
Not necessary but is helpful for our users.
Well where do you think we should do that.
It has to be on commit.
This is where that all of that happens.
So what I'm going to do here.
In fact I can go ahead and coming this out.
We don't need that.
It was just that was just for our debating debugging purposes.
So right here I can go ahead and say something like this.
I need to clear what's inside here.
Now how do we access what's inside here.
Well what's inside here.
It's always this no do item.
Right.
So that means I can come and say self dot no do not the bound property but the actual property and I'm
gonna set it to just empty like this clear field just like that's it.
Every time we hit Enter it's going to go ahead and do all the business here.
Add the item and then we're gonna clear.
Is that true.
Let's save this and run
look at this.
Enter in Whyalla.
It's clear and we can see the place holder text again Hello.
Enter in it's clear and so forth.
Right.
Very cool.
Now one last thing here which is crucial especially if you were running this application on your device
or even if the settings of my simulator here dictated that it showed the keyboard because it happened
right the moment you have text field it keyboard should show.
But now because I'm developing it just connected to my keyboard here that's why you don't see something
showing here keyboard but in real life the keyboard will show.
So we need to account for that.
Now with Swifty why we don't have a way yet of just directly dealing with our keyboard.
However what we can do we can use the UI Kit.
Right.
Methods or functions or framework and say something like this UI application.
So if your application says it is the centralized point of control and coordination of apps running
Iowa.
So this is the top class if you will in this case here I'm going to say I want to invoke the shared
Singleton in once a dot I want to go to the key window because it will have everything that I need and
I'm going to say the end editing like this.
And when I pass here to be true these just says OK if we have our keyboard here the moment you hit enter
well guess we are going to remove that keyboard so that the users can just focus on what's there.
We're not going to see the difference here again because I don't have it showing here because we're
developing so it just connects to my keyboard.
So no need to show here.
Very good.
So like that we have our working application now.
There's a lot of code all over the place.
What I want you to do because you should know how to do this by now especially or our strikes here.
How about moving this to a new file create a new file called row or view and then just move that over
there and you call so that you don't have this in one big file here.
And if you want you can also move this method here into a different file and then call it here or whatever
you want.
So go ahead and do that.
It's a good exercise for you.
Congratulations if you were able to get to this point here.
This is a huge milestone because we've learn about a lot of things.
So what I want you to do if at this point you feel like the learning curve is starting to get a little
bit steeper which I don't think it is.
But just in case I would recommend you two to really watch these videos a couple of times more because
remember these figures are there for you.
So you can always watch them so that you understand exactly what we're doing.
And if you have questions of course do ask them and go from there but I recommend you if you're feeling
like a little bit uncomfortable right now that's totally normal.
Just know that go back and re watch them and take notes if you need.
And remember always code along with me if you can that is in fact the most important thing.
That way you will practice coding which is exactly what we need you to do.
Congratulations.
And I'll see you in the next video.