 iOS Code Review | Curated code improvement tips

By  iOS Code Review

Bi-weekly newsletter amplifying code improvement tips from the Apple developer community in a bite-sized format. Swift, Objective-C, iOS, macOS, SwiftUI, UIKit and more. Curated by Marina Gornostaeva and published every other Thursday.

Bi-weekly newsletter amplifying code improvement tips from the Apple developer community in a bite-sized format. Swift, Objective-C, iOS, macOS, SwiftUI, UIKit and more. Curated by Marina Gornostaeva and published every other Thursday.

By subscribing, you agree with Revue’s Terms of Service and Privacy Policy and understand that  iOS Code Review | Curated code improvement tips will receive your email address.

1.27K

subscribers

26

issues

#26・

 iOS Code Review | Curated code improvement tips - Issue #26

.tabBar accessibility trait is almost magical when it comes to making a custom tab bar view behave like a system one.

 
#25・

 iOS Code Review | Curated code improvement tips - Issue #25

The new #unavailable attribute has been added in Swift 5.6 (Xcode 13.3) - we can now check for older OS versions directly: if #unavailable(iOS 15.0) { /* this code will run on iOS 14 and below */ }

 
#24・

 iOS Code Review | Curated code improvement tips - Issue #24

This thread is not about the literal API, but rather a bunch of things that are good to know and be aware of when building accessible products. I would love to know — how do you review code for accessibility?

 
#23・

 iOS Code Review | Curated code improvement tips - Issue #23

Great thread, nothing to add 😌 Excited to see that Natalia is back to blogging. She posts interesting content regularly, I wish I could feature all of it! Make sure to follow her on Twitter.

 
#22・

 iOS Code Review | Curated code improvement tips - Issue #22

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 Notification…

 
#21・

 iOS Code Review | Curated code improvement tips - Issue #21

You can dispatch a Task to the main actor two ways - by explicitly calling MainActor.run or by annotating the closure with @MainActor. These two ways have different behaviour. If already on the main thread, the former will run immediately but the latter will …

 
#20・

 iOS Code Review | Curated code improvement tips - Issue #20

When new APIs are introduced at WWDC, we can't use them right away in apps supporting previous iOS versions. And when the time comes, we already forgot about them. @onmyway133 shares a collection of reminders about cool and useful APIs that were introduced in…

 
#19・

 iOS Code Review | Curated code improvement tips - Issue #19

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

 
#18・

 iOS Code Review | Curated code improvement tips - Issue #18

Here's an interesting thread where people share how they document where the app saves things and how they like to organise constants. Lots of opinions - some prefer enums, others prefer extensions on UserDefaults. I personally like to use enums as shown in th…

 
#17・

 iOS Code Review | Curated code improvement tips - Issue #17

One of my favourite combinations of Swift's features:

 
#16・

 iOS Code Review | Curated code improvement tips - Issue #16

This is 100% my favourite way to organise assets - images or SF symbols, and even localisation strings. The best part is that you can easily check in unit tests that none of the assets are missing (or misspelled). Just conform your enum to CaseIterable and te…

 
#15・

 iOS Code Review | Curated code improvement tips - Issue #15

Adding a shim layer is a great way to approach moving to Swift in an Objective-C codebase. I can confirm from hands-on experience practicing it successfully on large ObjC projects.I had this tweet saved in bookmarks for a while, thinking maybe I'll write an a…

 
#14・

 iOS Code Review | Curated code improvement tips - Issue #14

There are multiple problems with splitting words by punctuation and whitespace - even in English "shouldn't" would split into two 'words'. And some languages don't even have spaces. Full article: Three Ways to Enumerate the Words In a String Using Swift by @s…

 
#13・

 iOS Code Review | Curated code improvement tips - Issue #13

On iOS 15, iOS might pre-warm your app by initialising the app delegate & co few minutes before the user launches the app. application(:didFinishLaunching:...) will be called when the app is finally launched, but other resources are loaded earlier. The cu…

 
#12・

 iOS Code Review | Curated code improvement tips - Issue #12

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

 
#11・

 iOS Code Review | Curated code improvement tips - Issue #11

Once I spent a whole day debugging a text truncation issue in SwiftUI. I had a list of views with multiline text in each. All was good, but on rare occasions one of the views would have truncated text. It would be seemingly random - the same item would be tru…

 
#10・

 iOS Code Review | Curated code improvement tips - Issue #10

While it's undoubtedly a superior way to write asynchronous code, I generally stayed away from async/await-related tips, because no one could really use them yet. I wrote about the issues few weeks ago. But not for much longer!Xcode 13.2 beta was released yes…

 
#9・

 iOS Code Review | Curated code improvement tips - Issue #9

SwiftUI previews can be very handy for other use-cases besides previewing SwiftUI views. You can use previews to preview UIKit views, which can save you dozens of hours in rebuilding to see your changes:

 
#8・

 iOS Code Review | Curated code improvement tips - Issue #8

Considering to start using async/await for real? Here are some things worth knowing before you do. Backporting to older iOS versions is proving challenging and might not happen; and a few serious issues and crashes have been found on the current version shipp…

 
#7・

 iOS Code Review | Curated code improvement tips - Issue #7

It's almost a tradition now to start the newsletter with a tip about an obscure Combine issue... This time, it turned out that breakpointOnError() crashes apps. To solve this, you can make an extension that conditionally uses this only if debugger is attached…