iOS Closures in Swift Building Standard Library Functions Flat Map

flatMap deprecated (Swift 4.2) ?

Hi, what would be the function to achieve the same result as the one obtained with flatMap ? i.e.: flattening an array of arrays to an array ?

1 Answer

Rogier Nitschelm
Rogier Nitschelm
iOS Development Techdegree Student 5,460 Points

In Swift there were a few use-cases for using flatMap. Removing nil-values from an array. And flattening an array of arrays for example.

Removing nil-values with flatMap is being deprecated. Instead you can use .compactMap for that. You can still use flatMap to flatten an array of arrays.