1 00:00:08,270 --> 00:00:14,840 What we can do also is we were able to use our ternary operator here to change the background. 2 00:00:14,960 --> 00:00:19,580 And we also were able to change indeed our image. 3 00:00:19,580 --> 00:00:26,150 The next thing I want to add actually is I'm going to also make sure that the whole opacity of as we 4 00:00:26,150 --> 00:00:31,400 check things to change the passive as well depending on our is done variable. 5 00:00:31,400 --> 00:00:37,030 So I'm going to put this behind there like that and I'm going to add dot opacity. 6 00:00:37,110 --> 00:00:38,150 Oh there we go. 7 00:00:38,240 --> 00:00:43,440 Opacity and when I also put inside here I'm going to say self. 8 00:00:44,000 --> 00:00:45,140 Dot is done. 9 00:00:45,170 --> 00:00:51,810 Depending what it's done or not I'm going to go ahead and 0 dot three else. 10 00:00:51,890 --> 00:00:53,120 I'm going to make it one. 11 00:00:53,120 --> 00:00:55,280 So if is done. 12 00:00:55,280 --> 00:00:56,900 Meaning they have checked. 13 00:00:56,900 --> 00:00:58,760 I want it to be kind of hidden. 14 00:00:58,760 --> 00:01:02,330 So the passive is going to be lower which means it's going to be kind of hazy. 15 00:01:02,410 --> 00:01:02,980 Right. 16 00:01:03,090 --> 00:01:06,610 Ellis is just going to be complete visible OK. 17 00:01:06,730 --> 00:01:07,830 Save that and run 18 00:01:11,780 --> 00:01:14,440 its add something of course. 19 00:01:15,040 --> 00:01:15,440 Look at it. 20 00:01:15,940 --> 00:01:18,040 Now would change the opacity as well. 21 00:01:18,040 --> 00:01:18,610 Come back. 22 00:01:18,610 --> 00:01:19,920 It all comes back to life. 23 00:01:20,290 --> 00:01:23,280 Not necessary but something that I wanted to show you. 24 00:01:23,380 --> 00:01:27,430 And you can see here the pattern is that you can do all sorts of things to a user interface. 25 00:01:27,430 --> 00:01:30,820 That's the beauty of swift UI isn't it. 26 00:01:30,820 --> 00:01:31,180 Very good. 27 00:01:31,180 --> 00:01:36,580 So next we're going to do is we need to actually get this time added right now. 28 00:01:36,610 --> 00:01:43,060 I'm not going to code and boring you with all the details that will allow us to get this time I go as 29 00:01:43,060 --> 00:01:45,280 they call in our application here. 30 00:01:45,310 --> 00:01:50,310 So it's a function that I found online that somebody wrote and I haven't want to share with you I want 31 00:01:50,350 --> 00:01:54,380 a copy and I'll put it here so that we can then invoke and call it. 32 00:01:54,430 --> 00:02:00,280 It's nice in recommended to use the work that other people have used or have created for us. 33 00:02:00,280 --> 00:02:06,190 So in this case just a little function a little library that transforms the current data that we are 34 00:02:06,190 --> 00:02:12,910 adding Our no do item and then transforms it into a time ago or in this case added a few seconds ago 35 00:02:12,940 --> 00:02:14,050 and so forth. 36 00:02:14,050 --> 00:02:14,530 And there we go. 37 00:02:14,530 --> 00:02:18,250 So this is the function that I'm telling you told you about. 38 00:02:18,250 --> 00:02:24,820 So here's the link where you can go and read more and see what other people are doing and so forth so 39 00:02:24,940 --> 00:02:28,100 I suggest you if you were interested in learning more about it just go there. 40 00:02:28,120 --> 00:02:28,320 OK. 41 00:02:28,330 --> 00:02:35,470 So this is a very simple function called Time a ghost in state so it requires you to pass a date object 42 00:02:35,470 --> 00:02:42,670 of course meaning the time that whatever item was added and you can either make this numerical date 43 00:02:42,700 --> 00:02:46,290 false or true meaning if you want to show the American dates and so forth. 44 00:02:46,300 --> 00:02:47,440 OK so there we go. 45 00:02:47,470 --> 00:02:48,490 There's a lot of code here. 46 00:02:48,490 --> 00:02:55,480 But most importantly only dies he takes the date that we are passing and converts it using the N S S 47 00:02:55,480 --> 00:03:01,480 calendar and makes it all look something like this one year ago last year and so forth. 48 00:03:01,480 --> 00:03:07,150 So now the reason why I'm showing this or the reason why I'm adding even this it's unnecessary for us 49 00:03:07,150 --> 00:03:13,030 at this point because we're not saving everything all of these to dos so far inside of our application 50 00:03:13,030 --> 00:03:14,730 or in database or some sort OK. 51 00:03:14,830 --> 00:03:21,190 So it will make more sense to once we start saving everything in our database or inside of our device 52 00:03:21,610 --> 00:03:27,280 because when we get out of our application we come back two days three days later we are going to be 53 00:03:27,280 --> 00:03:30,910 able to see the items that we added in the days and so forth. 54 00:03:30,910 --> 00:03:35,920 So then it will make more sense to see when items were added at this point here. 55 00:03:35,950 --> 00:03:40,590 It just there for us because we just want to be able to have that in place. 56 00:03:41,200 --> 00:03:43,630 OK very good. 57 00:03:43,630 --> 00:03:51,190 So now that we have our time ago since one little trick I'm going to show you a side note if you have 58 00:03:51,190 --> 00:03:55,390 functions that are this long usually it's nice to kind of fold them. 59 00:03:55,420 --> 00:04:02,440 So what do you do is you say command and click and then there is this mechanism called Fold click on 60 00:04:02,440 --> 00:04:05,380 that it goes ahead and collapse the whole function. 61 00:04:05,530 --> 00:04:08,940 And if you want it back you can just double click and shows there. 62 00:04:08,940 --> 00:04:09,150 OK. 63 00:04:09,190 --> 00:04:16,710 So it's pretty handy to kind of get your code all organized and not to bloated. 64 00:04:17,530 --> 00:04:17,840 OK. 65 00:04:17,850 --> 00:04:20,520 So how do we use this time ago since good. 66 00:04:20,530 --> 00:04:23,870 This has to be called Where here. 67 00:04:23,920 --> 00:04:24,750 Right. 68 00:04:24,850 --> 00:04:27,720 So we have to go something like this. 69 00:04:27,760 --> 00:04:32,380 So in this case here we have to come down here and say something like like that. 70 00:04:32,380 --> 00:04:37,180 And of course we pass let's say we didn't see what's going to happen 71 00:04:42,270 --> 00:04:45,600 if you add something like that say just now. 72 00:04:45,600 --> 00:04:52,140 So this is actually going to our function that we created and looks at the time we added things and 73 00:04:52,170 --> 00:04:57,130 that's all the computation and is going to say come down here just says just now. 74 00:04:57,220 --> 00:04:57,440 OK. 75 00:04:57,480 --> 00:05:02,190 Because it was less was greater or equal to three seconds ago. 76 00:05:02,190 --> 00:05:03,060 OK. 77 00:05:03,300 --> 00:05:07,170 Like I said this is not going to make it a lot of sense speak for us because everything is going to 78 00:05:07,170 --> 00:05:14,210 just show just now because we are not coming back at a later time to see all of these differences here. 79 00:05:14,220 --> 00:05:16,070 We could live it as it is. 80 00:05:16,140 --> 00:05:23,410 But let's be more specific here because however it's not truly when we added this item here is it. 81 00:05:23,580 --> 00:05:28,950 By the time we are showing here it could be a little bit after maybe not noticeably after because it's 82 00:05:28,950 --> 00:05:30,220 only milliseconds anyway. 83 00:05:30,240 --> 00:05:31,680 Just real fast. 84 00:05:31,680 --> 00:05:35,270 It could be a little bit after when we actually added the item. 85 00:05:35,340 --> 00:05:41,580 So if we go back to our own commit this is should be the place where we should be actually adding the 86 00:05:41,580 --> 00:05:47,970 time in fact this will be the place where if we want you do this to fright right away which means instead 87 00:05:47,970 --> 00:05:54,780 of just having an array we can have an array of data object items or no do items right. 88 00:05:54,870 --> 00:06:00,910 And then we could add that information along with the actual no do. 89 00:06:00,910 --> 00:06:10,670 OK so it's probably a good idea to do all of that inside on commit because we want to get the time when 90 00:06:10,670 --> 00:06:13,520 this was committed to add there. 91 00:06:13,520 --> 00:06:16,330 So really what are we going to do going to make a variable. 92 00:06:16,330 --> 00:06:20,590 So let's go back to our continent view here and going to say at St.. 93 00:06:20,810 --> 00:06:26,330 And I would say var it's just a time ago string this like this. 94 00:06:26,330 --> 00:06:32,420 And while we here we can just go ahead and make it empty like that text field so this is on comment 95 00:06:32,660 --> 00:06:38,180 dot time ago and I want to set it to what time ago right. 96 00:06:38,180 --> 00:06:46,450 We are not able to see it here because we need to actually have this method inside. 97 00:06:46,460 --> 00:06:52,340 So to simplify our lives I'm going to take this function and put inside 98 00:06:54,700 --> 00:06:59,450 of it's going to put it inside of our here. 99 00:06:59,450 --> 00:07:02,140 So this is going to be inside of our view. 100 00:07:02,200 --> 00:07:02,380 OK. 101 00:07:02,390 --> 00:07:05,380 Content view that we will have access to it. 102 00:07:05,410 --> 00:07:06,550 So right there. 103 00:07:06,550 --> 00:07:11,650 Make sure you are outside of the actual H stacks and everything. 104 00:07:11,650 --> 00:07:12,520 So there we go. 105 00:07:13,060 --> 00:07:18,190 So to make I want to do here is I'm going to create a at State 106 00:07:22,350 --> 00:07:30,460 var in this is gonna be just time ago just a simple explicit string am to 1 when I do the same thing 107 00:07:30,600 --> 00:07:31,550 to our row. 108 00:07:31,550 --> 00:07:34,860 That way we have that reference as well so turn down here. 109 00:07:36,190 --> 00:07:39,940 Looks like we have an extraneous one Skip and delete that. 110 00:07:40,830 --> 00:07:44,460 And I'm going to add it there as well. 111 00:07:45,210 --> 00:07:52,290 And of course this is not going to work right now because all I have to do is pass our time. 112 00:07:55,330 --> 00:08:02,030 Self that time I go as such and I can interpolate it as well. 113 00:08:02,200 --> 00:08:03,970 String interpolation of course 114 00:08:08,250 --> 00:08:09,350 I say added 115 00:08:15,840 --> 00:08:16,780 like this. 116 00:08:16,860 --> 00:08:17,380 Very good. 117 00:08:17,400 --> 00:08:24,440 So we're able to get that variable and most importantly now that we have this function set of our view. 118 00:08:24,500 --> 00:08:30,300 In fact let's go ahead and close it or fold it that way it's easier for us to organize our code. 119 00:08:30,300 --> 00:08:39,510 So I'm going to come up here what is more important in before instead of our own commit right above 120 00:08:39,630 --> 00:08:43,900 our right above where we're adding our items into our array. 121 00:08:43,980 --> 00:08:50,520 When I say Self that time ago is gonna be equal to time ago. 122 00:08:50,550 --> 00:08:57,190 There we go and I'm just gonna go ahead and pass the date like this the object. 123 00:08:57,350 --> 00:09:01,100 So each time we are adding we hit on commit. 124 00:09:01,300 --> 00:09:05,600 We're going to also create looks like we have to pass a few things self. 125 00:09:05,600 --> 00:09:11,740 There we go because it's inside of our enclosure here case of self that time ago sin state we passed 126 00:09:11,740 --> 00:09:20,900 the date so swift knows right away to passing the date that the date when we hit our own commit we hit 127 00:09:20,900 --> 00:09:27,350 our enter button so that happens we put that in that variable and then because that variable here is 128 00:09:27,350 --> 00:09:33,470 of course state it's going to be able to actually put in that time ago variable which indeed we can 129 00:09:33,620 --> 00:09:35,510 add inside of our item here. 130 00:09:35,510 --> 00:09:42,760 So at this point here let's see our no do we can go ahead and pass our No. 131 00:09:42,890 --> 00:09:44,540 Our item. 132 00:09:45,530 --> 00:09:46,100 Let's see. 133 00:09:46,100 --> 00:09:57,700 I think I need to add state that time go yes this is just gonna be I'm gonna make this a string. 134 00:09:57,700 --> 00:10:00,880 That way we are forced to have to pass in as a parameter here. 135 00:10:00,880 --> 00:10:01,260 Very good. 136 00:10:01,420 --> 00:10:08,210 So this is gonna be see you have strain. 137 00:10:08,250 --> 00:10:09,200 Note Ray 138 00:10:12,390 --> 00:10:14,580 okay let's just go ahead and do this. 139 00:10:14,580 --> 00:10:15,490 No. 140 00:10:15,570 --> 00:10:17,410 Do it like this. 141 00:10:17,760 --> 00:10:30,200 And while uh we just won this no do item just pass our item and bullion ops item like this and we don't 142 00:10:30,200 --> 00:10:40,020 need to pass this bullion at all again it's just past time I go here is going to be self that time I 143 00:10:40,020 --> 00:10:51,580 go Okay let's save this now and run expected and it just looks like we have a lot of made a few mistakes 144 00:10:51,580 --> 00:10:55,200 there but we have to add the braces there. 145 00:10:55,220 --> 00:11:04,450 Okay let's check it out now and add it just now you can go ahead and say add and there you go. 146 00:11:04,450 --> 00:11:09,220 So everything else is now working out like I said the difference is here we see still the same just 147 00:11:09,250 --> 00:11:15,280 now but at least we know when we are actually saving things the database and the dates that are being 148 00:11:15,280 --> 00:11:20,470 saved are going to be the correct ones because it's right when we hit comet or enter. 149 00:11:20,560 --> 00:11:27,290 That's where that's when we pass our time ago and then put that in our object all right. 150 00:11:27,420 --> 00:11:27,740 Very good. 151 00:11:27,750 --> 00:11:28,950 So we're making good progress. 152 00:11:28,950 --> 00:11:34,880 There's a few things that I would like to address before we finish this awesome application here and 153 00:11:34,920 --> 00:11:36,960 we'll start doing those in the next video.