Member-only story

Swift Programming Language: Arrays Tutorial

Jesse L
3 min readDec 19, 2021

--

Hi everyone, welcome back. Today, we will be going over arrays in Swift. Arrays are a common data type that are used to keep collections of data into one singular array variable. Arrays are ordered and mutable, meaning that they can be modified after being created. In this article we will go over the basics of the array. This includes how to create and modify arrays along with accessing values with them. With this introduction out of the way, let’s get into it.

Arrays

Let’s see how we can start by creating an empty array:

var array:[Int] = []

By using this code, we have created an empty array which can store variables of the integer(int) data type. All the values in an array must be the same data type.

Now, let’s see how we can create an array with populated values:

var array:[Int] = [1, 2, 3]

As we can see in the example above, we added 3 integers into our array. Each integer, or item added into the array, is separated by a comma. Let’s print our array to see what it looks like:

var array:[Int] = [1, 2, 3]
print(array)
Output:
[1, 2, 3]

Accessing Values in an Array

--

--

Jesse L
Jesse L

Written by Jesse L

Hi, I'm a passionate technology enthusiast and lifelong learner. Beyond my technical pursuits, I'm also passionate about sharing my enthusiasm with others.

No responses yet