Member-only story
Make Your Swift Arrays Safe
Isn’t this missing in the language?
Difficulty: Beginner | Easy | Normal | Challenging
This article has been developed using Xcode 11.5, and Swift 5.2.4
The accompanying video is at https://youtu.be/CCMMmmmGuuA
Keywords and Terminology
Array: an ordered series of objects which are the same type
The problem
It is possible to “run off the end” of an array. This means that that you can get a nasty runtime crash which will throw your user out of the nice iOS App experience that they had.
There are various solutions to this problem. In this article, I’m going to cover just one: An extension that makes the use of any Array.
The Solution
By placing the solution in an extension, we can make sure that it is available anywhere in your project. That would be awesome!
We can have it something like the following: