Issue #49
Hi there, welcome to the 49th issue of iOS Code Review! I hope you enjoy reading through today's collection 💌
Try Setapp for free
The efficiency of +=
The +=
operator, when performed a non-trivial number times, is much faster than addition and assignment with +
. (the Twitter integration is temporarily out of commission, click on the image to read the thread)
Ranged line limit in SwiftUI
We can specify a number of lines as a range, and SwiftUI will reserve space for the lower bound - even if the text itself takes less space (available from iOS 16)
Accessibility for custom SwiftUI views
Whenever we make a fancy custom control in SwiftUI, we don't have to spend time making it accessible by itself - instead we can use the .accessibilityRepresentation
modifier. Whenever VoiceOver navigation is used, SwiftUI will use the view created by this closure instead of our custom view. By using a system control in this representation, we save on effort while users will be happier 🤩
Custom scopes in Swift
I love this trick and use it quite a lot. Every set of curly braces is a scope - meaning that variables declared inside it are not available on the outside. Naturally, functions, closures, and if statements are scopes, but no one is stopping us from creating scopes whenever we want - the easiest way to do that is with a do {}
syntax.
Why, you ask? This allows to isolate some intricate logic, when you don't want to move out a piece of code to a separate function, but still want some extra separation inside the funciton. Last time I used it for calculating frames inside layoutSubviews
.
The importance of code ownership
Most of important and successful projects, even though they started off small, go through different phases that turn a proud shiny code into a piece of cryptic code everyone fears and despises.
In this article you'll read about how and why it happens, and find recommendations on making sure the code is properly owned - and thus maintained.
✌️
Alright, that's it for today!
I'm curious if you found any of the tips particularly interesting - let me know by replying to this email!
* this issue contains an affiliate link to Setapp
Member discussion