2 min read

Issue #8

Hi there,

It's Thursday again ✨ Got a few really interesting things to share. Let's dive straight in 👇


Status of async/await

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 shipped with Xcode 13 / iOS 15.0.

I was excited to start using this for real, but will be holding off until there's a more stable version out there.

Swift 5.5 has serious stack corruption bugs! - Compiler - Swift Forums

hi all, I’ve discovered several stack corruption bugs related to async/await which can be reproduced in simple test programs compiled with recent nightly toolchains. i have confirmed that two three four of these bugs are…

Catching errors

There are so many ways to write catch statements in Swift. It's as flexible as switch statements, and same as switch statements also verifies that all possible errors are handled, producing a compiler error otherwise.

Check out Sarun's article for detailed examples of each case. Here's the official language reference on patterns in Swift.

Modern dependency injection

Dependency injection as a design pattern can manifest in different ways - from passing dependencies at initialisation to service locators and 3rd party libraries. (here's a nice overview of the good old ways from 2019 by @kofse)

Inspired by SwiftUI's @Enviroment, nowadays dependency injection can be made simpler and easier to use, thanks to Swift's latest features such as static subscripts, extensions, and property wrappers:

Dependency Injection in Swift using latest Swift features - SwiftLee

Dependency Injection using latest Swift features allows you to mock data, and write tests easily without 3rd party dependencies.

Margins on UIStackView

Did you know that UIStackView supports layout margins out of the box? With one small boolean property isLayoutMarginsRelativeArrangement we can ask the stack view to lay the content within its layoutMargins instead of its edges. And it respects safe area out of the box, thanks to UIView's insetsLayoutMarginsFromSafeArea which is true by default.

If you want to learn more about the layout margin system in UIKit, I gave a whole talk about it at NSSpain in 2019 :)

🤘

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 🙌