2 min read

Issue #19

Hi there,

The world is still a mess, but I'm really excited to bring you some learnings today. Enjoy! 🙌


The Code Review Pyramid

What to look at in a code review? Check out this infographic shared by @gunnarmorling. Also available on the blog: The Code Review Pyramid

Struct properties - var or let?

Found this conversation thread on pros and cons of making properties in structs  var vs let. I like the take by @myell0w, and you'll find even more opinions in the thread.

Decoding corrupted arrays with Codable

By default, decoding an array of Codable will fail if one of the elements fails to decode. That's not obvious behaviour - and it's not always desirable.

The common way to solve this is to decode as an array of wrapper objects where the model is optional, and compactMap it after. For concrete implementation details, check out the article:

Decode an array with a corrupted element | Sarunw

When working with an unstable, legacy, or third party API, you might get a malformed object in an array. Learn how to decode a JSON array with corrupted data in Codable safely.

Fixing SwiftUI preview pausing

Turns out, structure of the code affects how SwiftUI previews are functioning. For example, changing the default value of a property will pause previews, but if the property is computed - changing the body won't pause previews.

This is because live reloading is implemented using @_dynamicReplacement attribute, which only supports replacing bodies of functions and properties. If you want to learn even more details, check out this article I wrote 2 months ago and forgot to include earlier 😀

Fixing SwiftUI’s Automatic Preview Updating Paused | Marina Gornostaeva

Understand why SwiftUI previews keep getting paused and how to improve the situation

A refactoring story

An entertaining and educational read about refactoring of a complex app. Good with a cup of tea 🍵

Refactoring Uber's Rider app • Space is Disorienting

There was a lot of discussion at the end of 2020 about Uber’s mobile apps. Many wondered aloud why we didn’t just refactor the app instead of rewriting it. I thought I’d add some context into where things were prior to the rewrite.

☮️

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 🙌