So what are we gonna do next is a we are going to play with the concept of whether the user tapped and
something needs to happen.
Meaning the whether use of tapped or not.
The row each item.
Now where does that need to happen.
Happen.
Action will the tap.
Action has to happen inside of these ro which means we still have to be inside of our no do row.
In this case here and all of that is happening where where are we creating this whole entity.
We are creating this whole entity somewhere really in this whole view here.
So this group or particularly in this entire v stack.
That means the beauty here the beauty with Swifty UI is that every view you can attach to it a lot of
modifiers but also a lot of methods or actions.
For instance I can come down here remember this is after a clip shape I can say Dot and I can go ahead
and say tap action.
Look at this the tab action.
There's a few of them there's the tab action where you pass the count and TAB action you just pass the
action K and there's tab action that just allows you to go ahead and create whatever you want to put
inside there.
OK so in this case just put a code somewhere I use that one there.
So what we want to happen here.
Well the moment these happened tab.
In fact let's for now go ahead and print something so we can see that this is indeed happening.
So it tapped in save and run.
We should be able to see in our console once the item is tapped the item look tab and says tapped pap
again this taps of this entire item here when tapped is going to go ahead and run this code here.
So this is useful to us.
What is it that we want to do.
What we want to tell the whole application here that when this is tapped something needs to change.
What is it that needs to change.
We want to make sure that when we tap we want to say that OK.
If they tap this that means they are done with this item or they want to check this off the list.
For that we have to put this variable in this case as you may have guessed it should be a bully and
we have to make it also a state right property because that would allow us to use that variable whatever
we want.
So in this case here I'm gonna go at the top of our no do remember struct here and when I say at state
again it was a var and I'm going to call this E's done is indeed a boolean which will be false in the
beginning.
Now I could have just gone and say is done is equal to False.
That's the faster way to do that.
Either way it doesn't matter at explicitly creating variables or implicitly doesn't matter.
OK which we can just leave it as it is right now.
So is done of course is always false.
In the beginning because when we add something it's not automatically done right.
So in this case here because we know these this is State wrapper is a state type bound to this is done
a variable we can then use that here.
So that means here I'm going to set it I'm going to say s dot is done like this.
In this case is gonna be true OK so let's save this in this go ahead and run of course nothing really
is going to be changing at this point here.
If I go like this and click it's going to be typed and I can come down here and also say if I want let's
go ahead and set it up.
In fact let me put this behind or I should say in front here little interpolation just for us to see
what's going on.
I like to be so self that is done such.
Let's run this at this point.
We should see the state when we tap.
So let's add something.
Enter tap tapped true.
Very good because it needs what was tapped and we said it too.
Is that true.
All right.
So life is good here.
But be the cool thing about having a variable in this case a state type wrapped variable is that in
this case because it's a boolean we can actually infer something else which is the toggle the toggle
you can always get it by saying that toggle like that.
It says here toggles between the boolean variables value which is very handy because it goes between
on and off.
OK so at this point here check out if I run this
look at this.
If I tap is true for tap again says false rightly toggle between two values billion two values.
True or false.
Which is very handy because we're going to use that.
OK.
So we have that done at this point.
But the actual action that we want to what we want to happen is not happening yet.
What is that we want to happen.
Well this is what we want to happen first for want to go ahead and if the item was tapped.
Meaning now this is true is done is true which which means the user wants to check this item as done.
We want then to make this whole view this whole row here have a different color a gray to signify that
this indeed has happened.
How do we do that again because this is done is indeed tied up with a state.
I mean it changes constantly when things change.
We can use that to our advantage.
How do we change this background on click.
Well where are we changing this background or where are we setting this background of our role.
Well we're setting it right here right.
Because we're saying here background and we pass into pink what we would have done here is put a if
statement that says if is done is true then we change color or else we change color to normal and so
forth.
But that could be a little bit complicated.
There is a better way to do that by using the ternary operator.
What is it ternary operator.
Well it turns our operators not just for safety y or swift in this case it's just a programming tool
that we can use to create if statement that are fairly confined and succinct.
What I mean by that is I could come inside here give a space I like to put it inside of brackets like
that.
OK.
This is going to be the statement or the expression that we want to evaluate inside here.
So I'm going to say in this case self dot is done.
If that's the case what I want to do is make the color pink.
But how do we create this actual code that should run.
We put a question mark like that to say if this is true then this happens.
Right.
Else how do we do else.
We just put calling like that else color is going to be great.
OK.
So this means if self is done we want to in fact this should be the opposite it should be gray because
if it's done and if it's indeed not done we want this to continue to be pink that's it.
So this is what we call the ternary operator this one two three items they're here inside.
This is what we are the expression that we are evaluating if this is true then immediate to that immediate
after the exclamation point.
We're going to run that or else we invoke the else with calling like that we run this look at that.
So now save this and give it a run.
Let's add something there and to look at this click while I now turn to color click it goes back to
see it's still true and false click.
Now it's true meaning this is done well.
And there we go.
Very good.
So the next time we're gonna do now that we have our ternary working and we have our is done toggle
everything is working perfectly.
The next thing we want to do is to change the square here which is we are adding here to change that
so that instead of a square it shows a check mark.
Well first of all I'm going to tell you that for a check mark.
You just say check mark like face in fact I'm going to go ahead and say here so you can see if I save
these and run you should see the check mark.
We're talking about and there you go.
There is our check mark.
But what I want you to do right now is the pauses video and use this same concept in this ternary operator
we use at the bottom here.
Use it here as well so that if indeed this is checked or this is done we're going to use the check mark.
Otherwise going to still have our square that we have there OK.
Go ahead and do that
all right I hope you were able to get that done but simply It's very simple again and we just go ahead
and put our expression here in this case is self
that is done if self that is done is true then I want the text to say check mark else I wanted to say
something different which will be square
save whoops.
Actually this has to be the exclamation point there.
All right save this and run.
We should see the results so we're looking for a hope.
All right.
The moment of truth click.
Nice.
Now change to then click back.
We see our square.
So we can add something else
don't be brave
can add something like this and continue.
So if I want to check that one it's very good.
Again check this one again check all of them.
I can go and check and the life is good.
All right.
So we are making real good progress here folks real good progress.
I hope you are getting more and more excited and you seeing other things you can do using binding and
text fields and of course using still using lists and in of course changing things depending on a toggle
variable.
All right.
So in the next video we're going to continue working on our application here we get him real close.
We're getting real close to have a full product here.
But there's still a few things that I'm going to show you here to complete this application.