Filtering in Swift

Filtering is an extremely important feature of Swift

Steven Curtis
The Startup

--

Photo by Pietro Tebaldi on Unsplash

Swift has loads of cool features. One of these is the use of higher order functions, and today this guide will focus on filter.

Difficulty: Beginner | Easy | Normal | Challenging

Prerequisites:

  • Be able to produce a “Hello, World!” iOS application (guide HERE)
  • This article talks about even elements, so familiarity with Mod would be useful (guide HERE)

Terminology

Array: An ordered series of objects which are the same type

Collection: A sequence of elements that can be traversed (as many times as you want) and can be accessed by an indexed subscript

Dictionary: The association between keys and values (where all the keys are of the same type, and all values are of the same type)

Filter: Acts on a collection type and returns an Array where the elements that are returned match the condition given in the Array

Set: An unordered collection of values (where all the values are of the same type)

Filter Arrays

A filter acts on any collection type (that is, an Array, Dictionary or Set), and returns an Array

--

--