Arrays

4 minutes
Share the link to this page
Copied
  Completed
In computer science, array programming languages (also known as vector or multidimensional languages) generalize operations on scalars to apply transparently to vectors, matrices, and higher-dimensional arrays. Array programming primitives concisely express broad ideas about data manipulation.

Transcript

Hello, welcome to the seventh tutorial swift basics series. And in this part we're going to look at arrays. Arrays are useful as well as multiple pieces of data to be grouped together, usually used when the data is similar or related to each other. And let's open up our project I'm going to show you a reason in Swift. So to declare an array, there are a few ways that a simple way can do in thought the array name, so I equals square bracket and then inside you put your array elements you do on six, five, and what and to access these elements, you do the array name, which in this instance, square bracket and then you do an index, aka, this will be the first second third but to access this one, you don't put one in as the first one, computer stuff is zero, so you put zero or one or two.

So we're gonna print the sensor Wind and I so I want to access for you. So we do one, run it and it's access five and obviously for the two in accesses one a notice calm so for now in no other way to do arrays in Swift is to rename it called square brackets again but inside here, what we can do is first name. I'll just write a second and I'll explain exactly what has been done to me. On first glance, you might think, Oh, it's the array called array has four values, when in fact it only has to value Bruce and Wayne whereas Here first name and a surname are actually the identify some pins zero, you would first name instead of putting one to access Wayne, you put surnames, that's pretty cool. So you can actually easily assign identifiers to them. So to access access Wayne, you would do you would do array name square brackets, and in here you may want to bear in mind, this is case sensitive.

So if I do locate, it puts nil because technically the date and the value at index lowercase s and u r n am E, so you need to make sure that you do the right case. Let's just comment this out a second. We will actually look into commenting a little more in a later tutorial. And to actually modify Actually, no, we need this again, to actually modify an array element is extremely easy. All you do is you access the array. So array on the put first name, put equals, sorry about that.

You put equals and then you put what you want to change it to but bear in mind once a certain element is of a certain data type, so this is strange, you can't actually assign a different type of alpha 4.8 your demeanor because this is a strength but if I assign a string to it, if a okay because it's a string datatype so I'm gonna print this out so you can actually see the change Okay, so we have wine and senate Bruce is sitting now so he's Batman. That's it. That is how you use arrays in Swift obviously locks it very valuable with different data type cannot be assigned at a certain enum because once it being assigned this value, it has a particular data type then in the next tutorial, we're gonna look at conditional statements. If you have any questions, feel free to message us or support us on our system that 30 K. The email will be in the description you can comment on this video or direct message messages via YouTube.

All the required links or source code will also be in the description and as usual, thanks for watching and have a nice day.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.