Swift Arrays are powerful

Arrays have such commonplace in programming. Swift Arrays in particular are easy to use and incredibly powerful. The amount of methods that we get for free from Swift is quite spectacular and often overlooked. Just look at the documentation for Swift Arrays. The list is lengthy. Of all the codebases that I have worked on, I only see a handful of these methods ever used. There are probably 4–5 methods used with the addition of creating extensions to get the functionality needed.
In this article, I will explain the use of predicates and how it helps us use all of these methods with our own custom data types. Also, you’ll see why it’s beneficial to use a variety of these methods in your code and not just the standard ones.
Use Custom Predicates
As you look through the documentation, you’ll see that most of the methods have an additional closure for the API that gives you the option to use a custom “predicate”. This is powerful and underutilized. Often, we’re not working with basic types like Ints or Strings, but rather custom data types that represent the data in our apps. Using a custom predicate allows for customization and using these methods on those custom data types. Let’s look at an example of using the min method:






