Exhaustive Swift Properties With Tuples
How can we get
switch
-like exhaustiveness when dealing with the properties of a type? The first step (and our first clue) is to treat the properties as a set. What if we put them in a tuple?[…]
So, to be clear, habitually shoving all properties into a tuple won’t scale well. But it is a useful tactic to employ when dealing with models, mocks or anything that has:
- naturally constrained state,
- logic that depends on the shape of said state, and
- a strong affinity towards change in the face of shifting requirements