Swift Array has an instance method, filter(_:), that removes unwanted elements from the resulting array.
If you have an array with optional values, you can easily filter out nil elements from that array using the compactMap(_:) method. In the following example, we have an optional string array, optionalColors. You can filter nil value out of any array by calling compactMap(_:) on that arra...
Swift concurrency comes with several interesting benefits. First, you can read the code we wrote from top to bottom. That makes the code easier to understand and reason about. Second, error handling is built into Swift concurrency. We don't need to unwrap an optional Error object to figure ...
Swift fundamentals When you have an Array of elements, and you want to drop all elements that don't match specific criteria from the Array, you're looking for Array'sfilter(isIncluded:)method. Let's say you have an array of words and you only want to keep the words that are longer ...
Swift fundamentals You can use Array's insert(_:at:) method to insert a new element at the start, or any other arbitrary position of an Array: Take the pain out of building and testing your app’s paywalls. With RevenueCat’s all new Paywalls you can custom build and remotely configure...
Learn, how to get the last element of a given array in Swift. Consider, we have the following array: var cars = ["Skoda", "Volvo", "BMW"]; To access the last element (BMW) from an above array, we can use the subscript syntax [ ] by passing its index. In Swift arrays are zer...
Multiple semesters of teaching Swift in iOS app development courses About this tutor › In order to create an empty array, you need to declare the type of the elements that are going to be in the array. For example: var myIntArray = [Int]() var myStringArray = [String]() or var...
In today's tutorial, you learn how to convert an array to a string in Swift. The Foundation framework defines a few APIs we can use. Which API you use largely depends on the type of the elements of the array. Let's get started....
This tutorial belongs to the Swift seriesSuppose you have an array in Swift, like this:var items = 1...3and you want to shuffle it, so that you get its items in random order.There are 2 ways to do that in Swift.One way is mutating the original array, and it’s using the ...
What is a Dictionary Dictionaries and arrays make up the collection types of Swift. Collections are exactly what they say: a collection of values. The difference between an array and a dictionary is how you get the values in and out of the collection. Ar