1 00:00:09,670 --> 00:00:15,370 So the next thing we need to work on here is how do we delete each of these items because we have them 2 00:00:15,450 --> 00:00:15,860 now. 3 00:00:15,880 --> 00:00:18,400 It's also important to be able to delete them. 4 00:00:19,030 --> 00:00:24,760 So one thing I noticed with a swifty why Now these may change it later because we are still in beta 5 00:00:24,790 --> 00:00:28,670 meaning it's not the full version yet they're still working on it. 6 00:00:28,720 --> 00:00:36,310 Is that with delete deleting items from our list we can swipe left and see that delete button or just 7 00:00:36,310 --> 00:00:40,600 go ahead and swipe left completely and then this item is gone. 8 00:00:40,900 --> 00:00:50,800 For that to work we can't just go ahead and say that on delete like this it somehow doesn't show what. 9 00:00:51,030 --> 00:00:54,040 OK it should work but it doesn't show up. 10 00:00:54,040 --> 00:01:01,930 So I figure out that the way for this to work is that we need to create the actual for each loop inside 11 00:01:01,930 --> 00:01:08,140 of a list meaning instead of having everything like this and then I just do like that we have to create 12 00:01:08,140 --> 00:01:08,760 a list. 13 00:01:08,800 --> 00:01:14,050 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 14 00:01:14,050 --> 00:01:16,180 go ahead and say just like what we did before. 15 00:01:16,200 --> 00:01:26,120 Here's in fact that can just go ahead and copy this and pass there and do what we did before say item 16 00:01:26,420 --> 00:01:31,220 in and then I'm gonna go ahead and say no do row. 17 00:01:31,430 --> 00:01:41,400 And when I pass the you know do such for No do I'm going to say item and then. 18 00:01:42,480 --> 00:01:48,280 And for that I'm not gonna pass anything into go I mean I say Self that time ago I said. 19 00:01:48,460 --> 00:01:49,360 OK. 20 00:01:49,590 --> 00:01:58,710 Only when you do that are you going to be able to come inside here and say dot on delete. 21 00:01:58,950 --> 00:02:00,390 Will that work. 22 00:02:00,460 --> 00:02:07,770 OK then I'm going to pass in a function here to delete and when I just say delete which we haven't created 23 00:02:07,770 --> 00:02:08,120 yet. 24 00:02:08,520 --> 00:02:09,320 OK there we go. 25 00:02:11,790 --> 00:02:14,190 It's called us delete item one thing is the best. 26 00:02:14,220 --> 00:02:24,560 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 27 00:02:24,570 --> 00:02:26,810 gonna be of index set type. 28 00:02:26,840 --> 00:02:29,010 So what is this index set type. 29 00:02:29,010 --> 00:02:34,620 Here is a collection of unique integer values that represent the indexes indexes of elements in another 30 00:02:34,620 --> 00:02:35,660 collection. 31 00:02:35,700 --> 00:02:40,830 So all of the collections that we are gonna pass through in this case just one collection which is our 32 00:02:41,400 --> 00:02:43,210 list of items here. 33 00:02:43,350 --> 00:02:46,110 It's going to be mapped with indexes. 34 00:02:46,110 --> 00:02:47,010 So that's what we're doing here. 35 00:02:47,010 --> 00:02:52,920 So the return type is going to be nothing because we don't wanna return anything anybody is going to 36 00:02:52,920 --> 00:02:54,950 be something like this. 37 00:02:55,020 --> 00:03:01,410 Now in this case here we want to convert these indexes into an array and get the index to where we want 38 00:03:01,410 --> 00:03:08,730 to get because there seems to be a bug that prevents us from using these offsets straight to get the 39 00:03:08,730 --> 00:03:09,800 index for each item. 40 00:03:09,870 --> 00:03:15,750 Because remember when we perform delete we want to be able to pass the index of each item that we want 41 00:03:15,750 --> 00:03:20,850 to delete because we don't want to just pass an arbitrary index and end up deleting something that it's 42 00:03:20,850 --> 00:03:26,610 not what we want to delete because everything instead of array which means each item instead of array 43 00:03:26,670 --> 00:03:28,020 has an index number. 44 00:03:28,410 --> 00:03:32,400 So we need to have that index number in order for us to delete the correct one. 45 00:03:32,400 --> 00:03:37,920 So that is why we're passing this this index set here contains a lot of things but we need to kind of 46 00:03:37,920 --> 00:03:40,790 parse the win Get what we want because of the bug. 47 00:03:40,830 --> 00:03:46,540 So we need to convert to index whatever we get from our index sets. 48 00:03:46,590 --> 00:03:50,670 So I'm gonna go ahead and say guard because we don't know if this is going to work and why. 49 00:03:50,700 --> 00:03:57,150 So guard ourselves if you will let index be equal to. 50 00:03:57,270 --> 00:03:59,970 I'm going to put everything inside of an array object. 51 00:03:59,970 --> 00:04:06,120 So in this case I'm just converting everything into an array which what is the thing is the offsets 52 00:04:06,180 --> 00:04:12,360 that we're passing these offsets there and then I'm gonna just go ahead and get the first item that 53 00:04:12,360 --> 00:04:13,860 I can find in that array. 54 00:04:13,890 --> 00:04:20,940 So it's gonna be just the item inside or the first item there and then say else I'm gonna just go ahead 55 00:04:21,150 --> 00:04:23,050 and return something. 56 00:04:23,190 --> 00:04:23,920 Nothing there. 57 00:04:23,950 --> 00:04:24,550 OK. 58 00:04:24,600 --> 00:04:30,190 So if something works if some doesn't work out as we intended we're just going to get it we're just 59 00:04:30,200 --> 00:04:34,080 going to leave this as it is and call it good. 60 00:04:34,080 --> 00:04:39,000 So now that we have our index in fact that can go ahead and say print in this case here I'm going to 61 00:04:39,000 --> 00:04:53,490 say removed a little interpolation here when say self dot no do list and then because it's NRA it can 62 00:04:53,490 --> 00:04:57,670 pass and index of which index the index that we just created there. 63 00:04:58,710 --> 00:05:06,480 OK so now if you call this method which is being actually called When we delete item we should be for 64 00:05:06,480 --> 00:05:10,530 now we gonna be able to see something hopefully if all goes well. 65 00:05:10,540 --> 00:05:17,840 So let's save this and run. 66 00:05:17,950 --> 00:05:22,920 Let's go ahead and add something and if we the moment you do like this. 67 00:05:22,920 --> 00:05:23,370 Look at that. 68 00:05:23,370 --> 00:05:29,580 Now you have that capability because we've attached its own delete to our list but it has to be this 69 00:05:29,580 --> 00:05:35,700 way because as I show you the way we had to before it wasn't allowing us to attach to own delete and 70 00:05:35,700 --> 00:05:42,120 just like that we can go like this in the moment you should delete it says removed the item added. 71 00:05:42,120 --> 00:05:48,870 Now it's still there which is OK because we actually like removing the item completely yet at this point 72 00:05:48,870 --> 00:05:50,870 here we're just showing the item inside. 73 00:05:50,880 --> 00:05:56,370 We're not removing anything that's why it's not going away even though it says removed it's not removing 74 00:05:56,370 --> 00:05:56,860 it. 75 00:05:57,030 --> 00:06:06,210 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 76 00:06:06,300 --> 00:06:12,760 method of any array that should have and then I'm going to remove at a certain index what index is going 77 00:06:12,760 --> 00:06:18,660 to be the index that we just created at this point here we actually going to remove the item from the 78 00:06:18,660 --> 00:06:28,890 list which means then the view will have to rebuild itself and remove that row row one enter. 79 00:06:28,890 --> 00:06:29,360 Look at this. 80 00:06:29,370 --> 00:06:38,460 If I just go like this and delete and now it's totally gone OK I can go ahead and add something else 81 00:06:39,720 --> 00:06:42,860 something else something else. 82 00:06:42,870 --> 00:06:45,260 So now I have all this functionality click here. 83 00:06:45,300 --> 00:06:45,750 It's done. 84 00:06:45,780 --> 00:06:46,950 I can still remove it. 85 00:06:47,040 --> 00:06:53,680 Done back can remove it or just click delete and it's gone. 86 00:06:53,880 --> 00:06:54,240 Why. 87 00:06:54,240 --> 00:07:01,800 Because we actually now removing from our do list and because no do list remember is in is bound to 88 00:07:01,800 --> 00:07:07,830 our view it knows exactly if something changes here it's going to go ahead and change the view as well. 89 00:07:07,830 --> 00:07:10,010 That's why we're able to not even see it there. 90 00:07:10,020 --> 00:07:11,550 It just removes itself 91 00:07:14,510 --> 00:07:15,890 all right. 92 00:07:15,890 --> 00:07:16,790 Here we go. 93 00:07:16,820 --> 00:07:23,450 And just like that we were able to put together a very nice working application. 94 00:07:23,450 --> 00:07:24,500 No do list. 95 00:07:24,500 --> 00:07:27,040 Now there's one more thing that we want to do here. 96 00:07:27,170 --> 00:07:33,200 Or two I should say it would be really nice if every time that we actually enter something we hit enter 97 00:07:33,470 --> 00:07:34,340 like this. 98 00:07:34,340 --> 00:07:39,110 We want to clear our text field just to get rid of everything nice inside there. 99 00:07:39,110 --> 00:07:39,820 Right. 100 00:07:39,830 --> 00:07:41,100 That'll be really nice. 101 00:07:41,120 --> 00:07:44,060 Not necessary but is helpful for our users. 102 00:07:44,990 --> 00:07:47,770 Well where do you think we should do that. 103 00:07:47,780 --> 00:07:49,320 It has to be on commit. 104 00:07:49,340 --> 00:07:52,390 This is where that all of that happens. 105 00:07:52,400 --> 00:07:53,650 So what I'm going to do here. 106 00:07:53,650 --> 00:07:55,970 In fact I can go ahead and coming this out. 107 00:07:55,970 --> 00:07:56,990 We don't need that. 108 00:07:56,990 --> 00:08:00,710 It was just that was just for our debating debugging purposes. 109 00:08:00,740 --> 00:08:04,070 So right here I can go ahead and say something like this. 110 00:08:04,100 --> 00:08:06,130 I need to clear what's inside here. 111 00:08:06,170 --> 00:08:08,570 Now how do we access what's inside here. 112 00:08:09,260 --> 00:08:10,950 Well what's inside here. 113 00:08:11,000 --> 00:08:14,960 It's always this no do item. 114 00:08:14,960 --> 00:08:15,910 Right. 115 00:08:15,950 --> 00:08:27,470 So that means I can come and say self dot no do not the bound property but the actual property and I'm 116 00:08:27,470 --> 00:08:35,440 gonna set it to just empty like this clear field just like that's it. 117 00:08:35,530 --> 00:08:39,790 Every time we hit Enter it's going to go ahead and do all the business here. 118 00:08:39,800 --> 00:08:42,060 Add the item and then we're gonna clear. 119 00:08:42,170 --> 00:08:42,680 Is that true. 120 00:08:42,710 --> 00:08:43,760 Let's save this and run 121 00:08:48,130 --> 00:08:48,600 look at this. 122 00:08:48,620 --> 00:08:49,840 Enter in Whyalla. 123 00:08:49,940 --> 00:08:54,950 It's clear and we can see the place holder text again Hello. 124 00:08:54,990 --> 00:08:57,160 Enter in it's clear and so forth. 125 00:08:59,460 --> 00:09:00,270 Right. 126 00:09:00,520 --> 00:09:01,460 Very cool. 127 00:09:01,460 --> 00:09:08,790 Now one last thing here which is crucial especially if you were running this application on your device 128 00:09:09,150 --> 00:09:17,110 or even if the settings of my simulator here dictated that it showed the keyboard because it happened 129 00:09:17,110 --> 00:09:20,140 right the moment you have text field it keyboard should show. 130 00:09:20,250 --> 00:09:25,080 But now because I'm developing it just connected to my keyboard here that's why you don't see something 131 00:09:25,080 --> 00:09:28,230 showing here keyboard but in real life the keyboard will show. 132 00:09:28,230 --> 00:09:29,790 So we need to account for that. 133 00:09:30,390 --> 00:09:36,720 Now with Swifty why we don't have a way yet of just directly dealing with our keyboard. 134 00:09:36,960 --> 00:09:40,970 However what we can do we can use the UI Kit. 135 00:09:41,090 --> 00:09:41,680 Right. 136 00:09:41,850 --> 00:09:49,940 Methods or functions or framework and say something like this UI application. 137 00:09:50,520 --> 00:09:56,250 So if your application says it is the centralized point of control and coordination of apps running 138 00:09:56,250 --> 00:09:56,530 Iowa. 139 00:09:56,550 --> 00:10:03,360 So this is the top class if you will in this case here I'm going to say I want to invoke the shared 140 00:10:04,290 --> 00:10:10,530 Singleton in once a dot I want to go to the key window because it will have everything that I need and 141 00:10:10,530 --> 00:10:14,130 I'm going to say the end editing like this. 142 00:10:14,130 --> 00:10:21,560 And when I pass here to be true these just says OK if we have our keyboard here the moment you hit enter 143 00:10:21,590 --> 00:10:28,490 well guess we are going to remove that keyboard so that the users can just focus on what's there. 144 00:10:28,570 --> 00:10:32,400 We're not going to see the difference here again because I don't have it showing here because we're 145 00:10:32,400 --> 00:10:35,310 developing so it just connects to my keyboard. 146 00:10:35,430 --> 00:10:37,220 So no need to show here. 147 00:10:37,350 --> 00:10:38,010 Very good. 148 00:10:38,070 --> 00:10:41,240 So like that we have our working application now. 149 00:10:41,340 --> 00:10:43,140 There's a lot of code all over the place. 150 00:10:43,140 --> 00:10:48,630 What I want you to do because you should know how to do this by now especially or our strikes here. 151 00:10:48,630 --> 00:10:56,520 How about moving this to a new file create a new file called row or view and then just move that over 152 00:10:56,520 --> 00:11:00,600 there and you call so that you don't have this in one big file here. 153 00:11:00,600 --> 00:11:06,420 And if you want you can also move this method here into a different file and then call it here or whatever 154 00:11:06,420 --> 00:11:06,690 you want. 155 00:11:06,690 --> 00:11:08,030 So go ahead and do that. 156 00:11:08,030 --> 00:11:09,810 It's a good exercise for you. 157 00:11:09,810 --> 00:11:12,870 Congratulations if you were able to get to this point here. 158 00:11:12,930 --> 00:11:17,420 This is a huge milestone because we've learn about a lot of things. 159 00:11:17,420 --> 00:11:21,840 So what I want you to do if at this point you feel like the learning curve is starting to get a little 160 00:11:21,840 --> 00:11:23,780 bit steeper which I don't think it is. 161 00:11:23,790 --> 00:11:28,620 But just in case I would recommend you two to really watch these videos a couple of times more because 162 00:11:28,620 --> 00:11:30,980 remember these figures are there for you. 163 00:11:30,990 --> 00:11:36,310 So you can always watch them so that you understand exactly what we're doing. 164 00:11:36,390 --> 00:11:41,400 And if you have questions of course do ask them and go from there but I recommend you if you're feeling 165 00:11:41,400 --> 00:11:44,420 like a little bit uncomfortable right now that's totally normal. 166 00:11:44,430 --> 00:11:47,330 Just know that go back and re watch them and take notes if you need. 167 00:11:47,460 --> 00:11:55,070 And remember always code along with me if you can that is in fact the most important thing. 168 00:11:55,140 --> 00:12:00,610 That way you will practice coding which is exactly what we need you to do. 169 00:12:00,640 --> 00:12:02,300 Congratulations. 170 00:12:02,310 --> 00:12:03,720 And I'll see you in the next video.