1 min read

Issue #22

Hi there,

Hope you enjoy today's collection 🙌

Updating @State values

It's not safe to update @State properties from any callbacks except those provided by the SwiftUI framework. Always use View.onReceive(_:perform:) to react to external changes and update the view state. Below is the example of how to subscribe to NotificationCenter notifications:

Disabling animation on a View

.animation(:_) modifier was deprecated in iOS 15, so now to disable animations we should use .transaction(_:) modifier that lets us customise the transition between two states. The doc says: "Use this modifier to change or replace the animation used in a view."

forEach vs for

There are some things a for loop can do that forEach can't, and vice versa. for offers a more fine-grained control flow, allowing to exit early with break, as well as to iterate conditionally with for ... where ... . On the other hand,  forEach allows to pass closures to it. In most cases though it simply comes down to personal taste!

jk! reduce is nice sometimes.

On (unnecessary) optimization

The Hidden Costs of Your Dependencies

Ever had to argument why adding a third party dependency to the codebase does not come for free? Here's an amazing concise article summarizing all the different aspects:

The Hidden Costs of Your Dependencies | Jason Zurita

Using a dependency isn’t always bad, but we should be intentional about how and when we use them and what the trade-offs are.


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 🙌