Member-only story

Swift Programming Language: Array Properties

Jesse L
3 min readDec 19, 2021

--

Hi everyone, welcome back. Today, we will be going over some of the most common and useful properties used with arrays in Swift. A basic tutorial on arrays in Swift can be found here. Arrays are a common data type that is capable of storing a collection of data within a single array variable. Arrays are ordered and mutable, meaning that they can be modified after being created. In this article, we will go over various properties of the array. With this introduction out of the way, let’s get into it.

isEmpty

Let’s start with the ‘isEmpty’ property of Swift arrays. The ‘isEmpty’ property will return a boolean value stating whether the array is empty or not. Let’s see an example:

var array:[Int] = []
print(array.isEmpty)
Output:
true

In this example, we created and used an empty array. The ‘isEmpty’ property is verifying that our array is empty as it returns true in our output. Let’s see what happens if we try this with a populated array:

var array:[Int] = [42, 23, 67]
print(array.isEmpty)
Output:
false

We know that our array is not empty, so we should expect that our output from the isEmpty property to be false. Looking at the output above, we can see that we got our expected result.

--

--

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