Last week, my colleague and I were working on a new feature. We decided to deliver most of it in UIKit, but with a little SwiftUI splashed-in.

Photo by Kelly Sikkema on Unsplash

The design wanted a few elements arranged vertically to be flush next to one another, no gaps, nothing.

Using a VStack to arrange our elements resulted in gaps as depicted by the horizontal black lines. Odd. We’d not set any padding on any of the elements, so what gives!

--

--

Long title, I know.

I don’t know about you, but my mind always jolts a little when I read something like below (line 9):

Okay, this is a small example, but it does illustrate the point: who speaks or writes like that! “if not bands is empty…”

For readability, I just had a brainstorm: extend the Collection protocol to provide something more readable:

Notice that it reads way more like English now: “if bands is not empty…”

The ugliness with the notting is done once, hidden away in the extension on line 3, leaving your code that uses it, très readable.

And because it is declared as an extension to Collection, you get this simple tweak for Array, Set and Dictionary at the same time. Noice!

Comments and improvements always welcome 😊

--

--

Andrew

Andrew

29 Followers

iOS Software Engineer. Punster extraordinaire. Part-time nerf herder.