1 00:00:00,700 --> 00:00:06,400 So will come back again in this lesson you're going to talk about a raise in swift on arrays and see 2 00:00:06,410 --> 00:00:08,320 if they're actually rather simple. 3 00:00:08,320 --> 00:00:14,650 So this jump into ex-coach and in a year I'm going to start a new project I'm going to make it a command 4 00:00:14,650 --> 00:00:15,370 line tool. 5 00:00:15,570 --> 00:00:23,320 I'm going to call it arrays in the swift and then in my arrays in swift and then I clear all of these. 6 00:00:23,310 --> 00:00:28,650 I don't need not I don't need that number say why are my array. 7 00:00:28,770 --> 00:00:38,540 And you could either directly define it by adding literal items to it say hello and then saying oh well 8 00:00:39,040 --> 00:00:40,930 that would become your array. 9 00:00:41,050 --> 00:00:46,600 Or you could actually choose it specifically to be an array of let's say a string. 10 00:00:46,930 --> 00:00:50,180 So then I know that this array is on a string. 11 00:00:50,200 --> 00:00:53,470 So let's call it a string array. 12 00:00:53,470 --> 00:00:57,490 Now if I want to see an object from it simply I'm going to say print. 13 00:00:57,580 --> 00:00:58,570 And what do I want to print. 14 00:00:58,570 --> 00:01:04,190 I want to print the string array object at index 0 for instance. 15 00:01:04,240 --> 00:01:08,310 And that would simply print our head or in this case for me. 16 00:01:11,630 --> 00:01:12,730 Right. 17 00:01:13,550 --> 00:01:15,600 And once he shows up here. 18 00:01:15,740 --> 00:01:22,880 Hello and then I could obviously do things such as having one array I could say strings or a dot of 19 00:01:22,880 --> 00:01:23,560 pens. 20 00:01:23,620 --> 00:01:27,130 And why would I want to append is I. 21 00:01:27,140 --> 00:01:28,350 Oh yes. 22 00:01:28,640 --> 00:01:34,520 And then of course I could get things such as the strings array that count. 23 00:01:34,700 --> 00:01:37,020 So that's kind of preinstall value for me. 24 00:01:37,280 --> 00:01:44,860 So if I go ahead and run you should be seeing 0 1 2 3 elements and it perfect. 25 00:01:45,020 --> 00:01:52,010 You could remove objects you could say a string array remove at and I'm going to remove object that 26 00:01:52,010 --> 00:01:53,800 is sitting in the first one. 27 00:01:53,970 --> 00:01:59,310 And now if I go ahead and say print the strings array we can see that. 28 00:01:59,330 --> 00:02:06,170 Now we don't have hello if you should only have a word on us perfect the way that we expect it to happen. 29 00:02:06,350 --> 00:02:13,220 So while you can use a swift array such as this one which are they can be annotated that they have a 30 00:02:13,220 --> 00:02:15,120 specifically a strings in them. 31 00:02:15,350 --> 00:02:17,780 You could also use Enas arrays if you want. 32 00:02:17,780 --> 00:02:22,460 So if you want you can say there my are a.. 33 00:02:22,520 --> 00:02:23,190 Array. 34 00:02:23,330 --> 00:02:26,190 That's going to be a.. 35 00:02:26,210 --> 00:02:26,670 Array. 36 00:02:26,680 --> 00:02:30,310 And then it's going to be an end a separate part in it. 37 00:02:30,410 --> 00:02:36,720 And then I have all the familiar stuff such as any with objects which I'm going to say is going to be 38 00:02:36,770 --> 00:02:37,680 hello. 39 00:02:37,920 --> 00:02:40,260 And then also going to be ward. 40 00:02:40,400 --> 00:02:47,560 There are some times that I prefer to use as arrays as opposed to us with there is or Leader or eyes. 41 00:02:47,720 --> 00:02:50,090 And we'll get to see them as the time comes. 42 00:02:50,090 --> 00:02:55,140 I've been actually in a few sections from now and I do a little game for you guys. 43 00:02:55,190 --> 00:03:01,640 I started with arrays then then I showed you how MSRA could actually benefit us in you know some of 44 00:03:01,640 --> 00:03:09,000 the stuff such as finding a certain item or removing a particular object in those kind of things and 45 00:03:09,010 --> 00:03:11,430 acetates might be a little bit easier to use. 46 00:03:11,570 --> 00:03:17,180 Even though arrays do all of those things but you know anisotropies might offer a little you know simpler 47 00:03:17,180 --> 00:03:23,220 ways it is simpler for me because that is for us because we know Objective-C a little bit better now. 48 00:03:23,330 --> 00:03:29,450 But in saying that arrays do almost absolutely everything that you know and SRI's do as well and they 49 00:03:29,450 --> 00:03:33,260 do actually beyond on one that they want to show you. 50 00:03:33,260 --> 00:03:38,300 Is this trend our index of say war. 51 00:03:38,330 --> 00:03:45,530 So I'm going to say preens and it is called the strings array index. 52 00:03:45,670 --> 00:03:53,410 I'm going to look for index of what I'm looking for index of is actually wall. 53 00:03:53,630 --> 00:03:56,140 So let's see what that one prints for me. 54 00:03:57,510 --> 00:04:04,120 So now when it runs it should say men because a world is not anywhere in there. 55 00:04:04,440 --> 00:04:07,320 So let's see why. 56 00:04:07,440 --> 00:04:13,140 That's because I actually made a mistake and that's because here we remove the first object. 57 00:04:13,140 --> 00:04:15,720 So our it doesn't actually have a word. 58 00:04:15,720 --> 00:04:18,150 So in a sort of word if I look for. 59 00:04:18,150 --> 00:04:18,950 Hello. 60 00:04:19,400 --> 00:04:21,880 I could actually see this a lot easier. 61 00:04:23,630 --> 00:04:27,800 Outsprint thing that it is an optional value zero. 62 00:04:28,000 --> 00:04:33,010 Now I'm much better off doing this thing is using an if. 63 00:04:33,010 --> 00:04:33,490 Let. 64 00:04:33,520 --> 00:04:39,050 So I'm going to say if let let's call it our index. 65 00:04:39,040 --> 00:04:44,620 He is going to be disvalue if this thing actually exists. 66 00:04:44,740 --> 00:04:50,490 He flips the data then Prince Freyne stands on. 67 00:04:50,800 --> 00:04:57,800 Hello he is X and then you remember that we are going to do this thing. 68 00:04:57,820 --> 00:05:00,750 We're going to say it's at index. 69 00:05:00,820 --> 00:05:05,430 And of course in the else we could print. 70 00:05:05,470 --> 00:05:08,870 It's not here or something to that effect. 71 00:05:08,890 --> 00:05:10,110 So let's run this 72 00:05:13,100 --> 00:05:14,100 on now. 73 00:05:14,250 --> 00:05:24,500 It says hello is at zero and if I were searching for iOS it would say US is in one in this situation. 74 00:05:24,750 --> 00:05:26,750 And so on and so forth. 75 00:05:26,970 --> 00:05:33,960 So that's about that you can use arrays are simply eyes you know declaring your array and getting its 76 00:05:34,300 --> 00:05:42,660 rotators explicit type if you want your arrays to have all different types and you don't want to explicitly 77 00:05:42,660 --> 00:05:46,950 mention that you can just drop this by its entirety or you could just say. 78 00:05:46,980 --> 00:05:55,710 And so this array could accept any kind of value let's say including a numeric integer value and then 79 00:05:55,790 --> 00:06:04,110 in here one of the challenges that we'll face is in here that you cannot invoke a method such as index 80 00:06:04,440 --> 00:06:08,260 for arrays that they don't have type. 81 00:06:08,330 --> 00:06:12,370 The type is any to remedy a situation like this. 82 00:06:12,370 --> 00:06:19,500 We could either adopt an equitable you know protocol that we'll talk about sometime in the future or 83 00:06:19,500 --> 00:06:25,980 we could use something like an S or a which doesn't have the type just like how and so is an objective 84 00:06:25,980 --> 00:06:27,820 c don't have to have types. 85 00:06:27,960 --> 00:06:30,030 They don't have have type in here either. 86 00:06:30,030 --> 00:06:33,190 So with that in mind that's about it. 87 00:06:33,240 --> 00:06:41,480 Arrays are adding or removing counting finding certain object and explicitly telling them their type 88 00:06:41,490 --> 00:06:46,600 or making sure that they are essentially typeless or they are any. 89 00:06:46,920 --> 00:06:49,920 And with that in mind let's move on to our next level. 90 00:06:49,920 --> 00:06:53,130 Next lesson that you're going to talk about dictionaries.