1 min read

Issue #12

Hi there,

How is your week going?

I hope you enjoy today's tips. Let me know what you found most interesting by replying to this email 🙌

Tired of translatesAutoresizingMasksIntoConstraints?

Two neat ways to deal with the good old (and annoying)  translatesAutoresizingMasksIntoConstraints 👍

Or like that:

let label = UILabel().forAutoLayout()

Type-safe identifiers

When we use string or int for identifiers, it can be easy to accidentally pass the wrong value to the function that takes a said identifier. @mecid wrote an article on using phantom types to make API that works with identifiers type-safe, so the compiler does the checking for us.

Understanding SwiftUI navigation

A nice short write-up on the current state of navigation in SwiftUI.

While the repo itself contains tools that you can use in your code, the readme goes over the issues that out-of-the-box navigation API has and potential directions for solving them.

It's a valuable resource for understanding how to deal with navigation better, even if you don't wish to use third-party code.

GitHub - pointfreeco/swiftui-navigation: Tools for making SwiftUI navigation simpler, more ergonomic and more precise.

Tools for making SwiftUI navigation simpler, more ergonomic and more precise. - GitHub

Improving old code

This is a great approach to working on old code. Old code can be improved significantly even by small refactoring - it's not always necessary to make big changes to make impact on code quality.

On non-fatal errors

We often write checks like this one:

guard let requiredValue = value else { return }

In reality, when this case happens, the user will just see that nothing happens in response to their actions, and the developer will never know about such cases. Force unwrapping and crashing the app is not the answer either.

Antoine discusses ways to approach this problem in his recent article.


Alright, that’s it for today.

Did you enjoy this issue? Let me know by pressing the buttons below, so I can improve the newsletter.

Got feedback? Want to see more, or less of certain kinds of tips? I’d love to hear from you. Reply to this email or reach out on Twitter via @ios_code_review 🙌