As an iOS developer who works with Swift almost every day, you will frequently encounter situations where you need to manipulate arrays to achieve desired results. Removing one or some elements from an array is one of these essential......
Overview Array sorting is the process of arranging elements in a specific order – either ascending or descending. Swift provides several built-in functions to sort arrays, allowing developers to write clean and efficient code.......
Shuffling an array means randomly re-arranging the elements of that array. This example-based, practical article will walk you through several different ways to shuffle a given array in Swift. Using the shuffle() method The......
Swapping 2 array elements means exchanging their positions in the array. For example, if you have an array like [1, 2, 3, 4] and you want to swap the elements at index 0 and index 2, you will get [3, 2, 1, 4] after swapping. This concise,......
The Fundamentals In the realm of Swift, the array filter() method is used for returning a new array that contains only the elements of the original array that satisfy a given condition. The syntax of the filter() method is shown......
Overview In Swift programming, the array map() method is used for transforming an array by applying the same operation to each element of the array using a specified transformation closure. The syntax of the map() method......
This practical, example-based article walks you through a couple of different approaches to calculating the average (the mean) of all elements in a numeric array (an array that contains only numbers) in Swift. No more wasting time;......
This practical, code-centric article will walk you through several different ways to calculate the sum of a numeric array (an array that only contains numerical elements) in Swift. Using the reduce() method You can use the reduce()......
Overview Swift provides several built-in array methods that can help you find the index of an element (when knowing its value or some of its characteristics) in a given array: firstIndex(of:): You can use this method to find the......
When developing applications with Swift, there might be cases where you need to reverse a given array, such as when you want to display an array of messages or comments in chronological order from newest to oldest (or vice versa). This......
This succinct, practical article will walk you through a couple of different approaches to determining the data type of a variable at runtime in Swift. Without any further ado, let’s get started. Using the type(of:)......
In the context of programming, concatenating arrays means joining two or more arrays into one array. This succinct example-based article will walk you through a couple of different ways to concatenate arrays in Swift (provided that the......