What we can do also is we were able to use our ternary operator here to change the background.
And we also were able to change indeed our image.
The next thing I want to add actually is I'm going to also make sure that the whole opacity of as we
check things to change the passive as well depending on our is done variable.
So I'm going to put this behind there like that and I'm going to add dot opacity.
Oh there we go.
Opacity and when I also put inside here I'm going to say self.
Dot is done.
Depending what it's done or not I'm going to go ahead and 0 dot three else.
I'm going to make it one.
So if is done.
Meaning they have checked.
I want it to be kind of hidden.
So the passive is going to be lower which means it's going to be kind of hazy.
Right.
Ellis is just going to be complete visible OK.
Save that and run
its add something of course.
Look at it.
Now would change the opacity as well.
Come back.
It all comes back to life.
Not necessary but something that I wanted to show you.
And you can see here the pattern is that you can do all sorts of things to a user interface.
That's the beauty of swift UI isn't it.
Very good.
So next we're going to do is we need to actually get this time added right now.
I'm not going to code and boring you with all the details that will allow us to get this time I go as
they call in our application here.
So it's a function that I found online that somebody wrote and I haven't want to share with you I want
a copy and I'll put it here so that we can then invoke and call it.
It's nice in recommended to use the work that other people have used or have created for us.
So in this case just a little function a little library that transforms the current data that we are
adding Our no do item and then transforms it into a time ago or in this case added a few seconds ago
and so forth.
And there we go.
So this is the function that I'm telling you told you about.
So here's the link where you can go and read more and see what other people are doing and so forth so
I suggest you if you were interested in learning more about it just go there.
OK.
So this is a very simple function called Time a ghost in state so it requires you to pass a date object
of course meaning the time that whatever item was added and you can either make this numerical date
false or true meaning if you want to show the American dates and so forth.
OK so there we go.
There's a lot of code here.
But most importantly only dies he takes the date that we are passing and converts it using the N S S
calendar and makes it all look something like this one year ago last year and so forth.
So now the reason why I'm showing this or the reason why I'm adding even this it's unnecessary for us
at this point because we're not saving everything all of these to dos so far inside of our application
or in database or some sort OK.
So it will make more sense to once we start saving everything in our database or inside of our device
because when we get out of our application we come back two days three days later we are going to be
able to see the items that we added in the days and so forth.
So then it will make more sense to see when items were added at this point here.
It just there for us because we just want to be able to have that in place.
OK very good.
So now that we have our time ago since one little trick I'm going to show you a side note if you have
functions that are this long usually it's nice to kind of fold them.
So what do you do is you say command and click and then there is this mechanism called Fold click on
that it goes ahead and collapse the whole function.
And if you want it back you can just double click and shows there.
OK.
So it's pretty handy to kind of get your code all organized and not to bloated.
OK.
So how do we use this time ago since good.
This has to be called Where here.
Right.
So we have to go something like this.
So in this case here we have to come down here and say something like like that.
And of course we pass let's say we didn't see what's going to happen
if you add something like that say just now.
So this is actually going to our function that we created and looks at the time we added things and
that's all the computation and is going to say come down here just says just now.
OK.
Because it was less was greater or equal to three seconds ago.
OK.
Like I said this is not going to make it a lot of sense speak for us because everything is going to
just show just now because we are not coming back at a later time to see all of these differences here.
We could live it as it is.
But let's be more specific here because however it's not truly when we added this item here is it.
By the time we are showing here it could be a little bit after maybe not noticeably after because it's
only milliseconds anyway.
Just real fast.
It could be a little bit after when we actually added the item.
So if we go back to our own commit this is should be the place where we should be actually adding the
time in fact this will be the place where if we want you do this to fright right away which means instead
of just having an array we can have an array of data object items or no do items right.
And then we could add that information along with the actual no do.
OK so it's probably a good idea to do all of that inside on commit because we want to get the time when
this was committed to add there.
So really what are we going to do going to make a variable.
So let's go back to our continent view here and going to say at St..
And I would say var it's just a time ago string this like this.
And while we here we can just go ahead and make it empty like that text field so this is on comment
dot time ago and I want to set it to what time ago right.
We are not able to see it here because we need to actually have this method inside.
So to simplify our lives I'm going to take this function and put inside
of it's going to put it inside of our here.
So this is going to be inside of our view.
OK.
Content view that we will have access to it.
So right there.
Make sure you are outside of the actual H stacks and everything.
So there we go.
So to make I want to do here is I'm going to create a at State
var in this is gonna be just time ago just a simple explicit string am to 1 when I do the same thing
to our row.
That way we have that reference as well so turn down here.
Looks like we have an extraneous one Skip and delete that.
And I'm going to add it there as well.
And of course this is not going to work right now because all I have to do is pass our time.
Self that time I go as such and I can interpolate it as well.
String interpolation of course
I say added
like this.
Very good.
So we're able to get that variable and most importantly now that we have this function set of our view.
In fact let's go ahead and close it or fold it that way it's easier for us to organize our code.
So I'm going to come up here what is more important in before instead of our own commit right above
our right above where we're adding our items into our array.
When I say Self that time ago is gonna be equal to time ago.
There we go and I'm just gonna go ahead and pass the date like this the object.
So each time we are adding we hit on commit.
We're going to also create looks like we have to pass a few things self.
There we go because it's inside of our enclosure here case of self that time ago sin state we passed
the date so swift knows right away to passing the date that the date when we hit our own commit we hit
our enter button so that happens we put that in that variable and then because that variable here is
of course state it's going to be able to actually put in that time ago variable which indeed we can
add inside of our item here.
So at this point here let's see our no do we can go ahead and pass our No.
Our item.
Let's see.
I think I need to add state that time go yes this is just gonna be I'm gonna make this a string.
That way we are forced to have to pass in as a parameter here.
Very good.
So this is gonna be see you have strain.
Note Ray
okay let's just go ahead and do this.
No.
Do it like this.
And while uh we just won this no do item just pass our item and bullion ops item like this and we don't
need to pass this bullion at all again it's just past time I go here is going to be self that time I
go Okay let's save this now and run expected and it just looks like we have a lot of made a few mistakes
there but we have to add the braces there.
Okay let's check it out now and add it just now you can go ahead and say add and there you go.
So everything else is now working out like I said the difference is here we see still the same just
now but at least we know when we are actually saving things the database and the dates that are being
saved are going to be the correct ones because it's right when we hit comet or enter.
That's where that's when we pass our time ago and then put that in our object all right.
Very good.
So we're making good progress.
There's a few things that I would like to address before we finish this awesome application here and
we'll start doing those in the next video.