2 min read

Issue #31

Hi there,

Did you enjoy the Apple event yesterday? Whether you're into the latest tech, or in the camp of anti-consumerism, hope you had a nice day 🙂

On Twitter it might seem that everyone is so excited about the new phones/watches/etc. But that's just the bubble. I, for one, will not be buying a new iPhone or watch any time soon - will keep enjoying my 2-year-old XS and series 5. To whomever needs to hear this, it's totally ok not to jump on buying the newest thing, but also it's ok to do so.

Now let's dive in, hope you learn something new today


On [weak] self (again)

The weak self subject is a bit worn, but check this out. Steve has a good general point that such everyday things should be as ergonomic and effortless as possible in a language.

Here Steve also shared an article on the topic of self in closures. It's sort-of-a-reply to another opinionated piece, but I really like it on its own. If you were looking for once-and-for-all answer to the question of when to use weak and when not, this might be it.

I promise no more weak-self related tips 😀

The Golden Rules of weak self | Chris Downie

Capturing self in a closure is a common thing to do in Swift, and one that hides a lot of nuance. Do you need to make it weak to avoid a reference cycle? Is making it weak all the time a problem?

Thoughts on massive observable objects

Having granular ObservableObject's is a good way to go. To avoid unnecessary re-renders, give the high-level views only the dependencies they need.

Actions in @Environment

Very important TIL-moment if you're embracing @Environment-based action closures such as OpenURLAction. They should be callable types, not closures - otherwise views that use this variable will re-render unnecessarily whenever the environment could change - for example, on rotation or going to foreground.

Callable structs look like functions to the user of the api, as if you used a typealias for the closure type. If you define a type (struct, enum or class) and add a function named func callAsFuntion() , you'll then be able to invoke it by using () - x() is equivalent to x.callAsFunction(). This supports custom parameters too. It's a pretty cool feature in Swift!

Slack's legacy codebase improvement story

Recently Slack shared how they improve their legacy mobile codebase in a 3-article series. Here's an 8-minute summary, in case you don't have 30+ minutes to read the original, which is also linked there.

Mobile App Refactoring Initiative by Slack | by Elye

A summary of how Slack stabilized, modularized, and modernized its mobile application code base

🤘

Alright, that’s it for today.

Did you enjoy this issue? Let me know by pressing the buttons below. If you enjoyed it, you can help grow the newsletter by spreading the word ☺️

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 🙌