3 min read

Issue #53

Hi there, welcome to the 53rd issue of iOS Code Review! It's so nice to be back πŸŽ‰

It's almost conference season πŸ€“ I'm going to a couple of conferences this autumn. I will speak at NSSpain and hopefully get a visa in time attend iOSDevUK. Will I see you there? Let me know if you're also planning to go, let's meet!
If you're not going to any in-person conferences, perhaps check out the online Mobile DevOps Summit by Bitrise, who are so kind to be sponsoring multiple issues of the newsletter ☺️

Also a small personal update: I've changed my last name to Vatmakhter - which is my grandparents family name. It's something I've been wanting to do for many years, and finally I could πŸŽ‰β˜ΊοΈ I'll slowly propagate it throughout my online presence - it's still me 😁

Join the Mobile DevOps Summit 2023 on Oct 4-5
A two-day, free event with 40+ workshops and sessions brought to you by 50+ industry-leading speakers from eBay, Reddit, AWS and more. Learn from real-world examples of successful Mobile DevOps implementations. Check out our speaker list

Enum-based sheet presentation

Displaying multiple sheets from one view can quickly lead to repetitive code segments in SwiftUI. By using an enum to represent which sheet to present, we can make the code more maintainable. This, and more learnings can be found in Antoine's article below.

image source: @twannl
Sheets in SwiftUI explained with code examples
Sheets in SwiftUI allow you to present a view on top of another. Learn how you can control multiple sheets using a generic solution.

Using #error

Swift has a compiler directive that allows us to issue a compilation error.
This can be useful in a few ways, for example to prevent the app from compiling in certain conditions.
One of my usecases is when you're iterating over a feature and want to merge to develop, and want to make sure the app can't be released in an unfinished state.

func calculateStuff() {
    #error("calculateStuff feature is not implemented!"

Here's Vincent sharing another scenario, where package authors can use #error in their example code, to bring user's attention where they need to fill out the api key.

Text + Text

A handly alternative to AttributedString in SwiftUI:

SwiftUI lets us to compile Texts using the + operator. You can apply certain modifiers (that return type is Text) to Texts and it still will work.  You can use string interpolation and put one Text into another one. And since SFSymbols are also text you can embed them too

A refactoring story

Every codebase has a piece of code similar to this. Here's Jon demonstrating a step-by step refactoring to make it error-proof:

Refactoring: How Do You Clear Up a Mess, Safely? | Quality Coding
When refactoring in small steps, sometimes you have to make a mess to clear up a mess. Download the code and walk through these refactoring steps.

Alright, that's it for today! Let's spread the good code vibes βœ¨πŸ§˜πŸŒˆβ˜€οΈ
Thank you to Bitrise for sponsoring this issue ❀️
And I always want to hear from you -just reply to this email :)