Hello, my name is Mark Nair and in these lessons, you'll learn about complex data types including array, dictionaries, enums, and sets. Collections in Swift let us use many objects as a group instead of having to use different constants or variables to keep track of every individual object. An array is a collection that has an ordered list of values. It looks like this. So here I have a constant called cities. Now that is equal to and I have quite a few names of different cities around the world, but you'll notice that they're in brackets. So different than strings we looked at before, but these are string values all separated by a comma within brackets and this is an array of values. So let's peak inside of cities to see what's in there. To do that, I'll just type cities and I'll run it. Clicking the arrow, you see over here it's the very same values that I have up here in line one. So I know that this is an array. If I option + click cities, let cities type of array of string so it's string inside of these brackets. To find a specific item in the array, we can do this, cities and then bracket and then the number of the item in the array. Now I'm using zero is the first number and you'll see when I run it, the result is Tokyo. The reason why zero is the beginning is because arrays in Swift start at zero. So we start counting zero, one, two, three. A lot of people get confused on this. So just remember in an array, the first item in the array right here, Tokyo is position zero, Delhi position one, Shanghai position two even though it looks like the third thing in the array which it is the third item but it's position zero, one, two. We can check if something is in the array like this. So I'm getting name of cities, the name of the array, dot contains and then in parenthesis, the information that I'm checking for. In this case, it's Taipei. When I run this, I will get true, so this responds with a Boolean value. To change the element in an array, it's the same thing I've done before. The name of the array, brackets, and then the specific location. So this time I will change position one. I will now make this equal to Cairo. Oh, I can't change it because I've made cities a constant, not a variable. So changing that which would help. Now I can change position of one cities to Cairo. Now I see that my order is Tokyo, Cairo. I've replaced Delhi with Cairo. Just keep in mind an array is very specific on where things exist in the array. I can add to the array with this. So the keyword is append and my popup menu here it says new element. I'll just accept that and it is new element of string, so Mumbai. Now when I append the element to the array, you'll notice that the very end of the array, that's where the element goes. It tacks it onto the bottom, the back of it, the end of it. I can also add to the array by adding another array to it, for example. So here I'm adding an array of two values, Osaka and Karachi, to the array of cities. When I run that, you'll see now my array cities is getting quite long and there is Mumbai, then Osaka and Karachi at the end. Of course, I could view this in line as well. I can add to a specific place of the array. Now in this case, I'm telling the array cities, cities, I want to insert some information to the array called cities. What I'm inserting is in the parenthesis a string called Paris, comma, and then the location at position one. Now instead of replacing Cairo, it just pushes Cairo down to position two. So Tokyo position zero, then Paris, then Cairo. Let's remove elements from the array. This will remove the element at position four from the array. Now right now, zero, one, two, three, four. That's Mexico City, running this removes the value of Mexico City. If we take a peak, I have removed it. We can actually keep that element that we have removed for use later on like this. This time, I'm gonna remove the element of position six, but I'm storing that in the constant removedCity. It's Amarillo, and then I can easily print. We can easily remove the first and last elements. Just like this, removeFirst and removeLast. And again, I could use these values in something else, Tokyo and Karachi. I can remove everything and that will give me an empty array right here. Let's take a look at how many items are now in that array. I'll do that with a count method and it is zero 'cause I've removed it all. Sometimes you won't know the contents of an array when you first create it. Well, we did this for other types that look like this. So I'm just establishing word as a type of string. For an array, it's similar. There are a couple ways. So let's set up a new array. So here's a new array of type String which is equal to an empty array. There's a shortcut for this. It looks like this. This is an array of strings just like that. You'll probably see both of these methods. Let's practice this a little bit. I'm going to append banana to new array and then I'm going to insert orange of position one of another array. That won't work, I'm getting a terrible error because another array really has nothing in it. There is no position one. It has to be position zero to make this work at the beginning. Oh, and little syntactical error there. And then I can assign a new array called fruitArray which is equal to new array plus another array. If I add and look into the count of fruitArray, I have two elements in it and I can always loop over that. And there we go. It's printing both banana and orange. Thanks for watching, stay tuned for the next lesson where I'll show you how to use dictionaries.