Member-only story

13 Useful Array Methods in Swift

Artturi Jalli
Better Programming
Published in
4 min readMay 17, 2021

Code on laptop
Photo by Blake Connally on Unsplash.

An array is a commonly used data type in Swift. It is like a list in which you store items (for example numbers). You are going to use arrays a lot as an iOS engineer.

To help you master arrays and improve your code, I wrote this guide that shows you built-in array methods and examples.

1. Array.filter()

Instead of creating a loop, you can use the array’s built-in filter() method to filter elements to a new array.

For instance, let’s filter numbers lower than or equal to 3 to a new array:

Output:

[1,2,3]

2. Array.map()

The map() method takes each value of an array, performs some action on it, and finally places the new value into a new array. This is handy and can be used instead of a for or while loop.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Write a response