3 min read

Issue #64

Hi there, welcome to the 2^6th issue of iOS Code Review! Only 9 days left until spring. Perfect time to learn something new!

Don't write recursive functions in Swift

Apparently recursive functions can cause a stack overflow. TIL! If your data is dynamic and the recursion can get unpredictably deep, better avoid it altogether and use a while loop instead.

Avoid using default enum case

I'm a big advocate for strong typing and compiler checks helping avoid bugs and speed up development. And the most basic example of that is switching over an enum. If we spell out all cases explicitly, when a new case is added, the compiler notifies us of all points that need changing.
If you have a colleague that still needs convincing, this is a nice short article on the matter :)

Swift enums and the danger of the default case
How not to lay traps for future developers

Previewing CIImage in the debugger

Did you know you can quick-look items in the variables pane of the debugger? That includes not only plain data such as strings and arrays, but also UIImage variables. Even more, a CIImage variable preview includes additional information such as transforms. Check out that little 👁️ icon in the debugger panel! Mike here shares a demo video in the tweet 👇

On separating UI and logic

Can't decide on the view / logic boundary? Ask yourself: “What if this feature should also work as a Command Line Tool?”. I've been personally using this approach for architecting a clear separation and API surface for the domain logic. I love seeing a full-feature article describing this way of thinking:

What if your feature was a Command Line Tool?
When working with UI, it can sometimes be ambiguous where to place business logic. By imagining our features as a Command Line Tool, this can become quite clear.
Setapp offers a collection of 240+ trustworthy, advanced apps under one simple subscription. You will find apps such as Spark Mail, Ulysses, Paste, Asset Catalog Creator Pro, DevUtils, Craft, Structured, Awesome Habits, and many more. Try Setapp for free

✌️
Alright, that's it for today! Let's spread the good code vibes ✨🧘🌈☀️
I'm curious if you found any of the tips particularly interesting - let me know by replying to this email!

PS. This time I'm trying a new way of embedding tweets. Send me your feedback on how that shows up in your email client.