Wednesday, March 13, 2019 [Tweets] [Favorites]

Exhaustive Swift Properties With Tuples

Joshua Emmons:

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:

  1. naturally constrained state,
  2. logic that depends on the shape of said state, and
  3. a strong affinity towards change in the face of shifting requirements

Comments

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment