View profile

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

 iOS Code Review
 iOS Code Review
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.
Xcode Releases
@guybrooker A recent post from Doug shows how much work remains to be done:

“as we said before, it’s technically challenging and we’re not 100% sure it’ll work out.”
Swift 5.5 has serious stack corruption bugs! - Compiler - Swift Forums
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.
Sarun W.
There are many ways to catch throwing errors in Swift.

Learn all of them here:
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:
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 :)
Sarun W.
You can add padding to your stack view content with isLayoutMarginsRelativeArrangement.

Learn more:

#ios #iosdev
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 🙌
Did you enjoy this issue? Yes No
 iOS Code Review
 iOS Code Review @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.

In order to unsubscribe, click here.
If you were forwarded this newsletter and you like it, you can subscribe here.
Created with Revue by Twitter.