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





Subscribe to our newsletter

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.

 iOS Code Review
 iOS Code Review
Hi there,
As I’m writing this, I am recording a show-and-tell video sharing a bit about my process creating this newsletter. I’ll share it on Twitter and in the next issue, so stay tuned :)
I hope you find something interesting in my collection today 👇

Implicit weak self is coming
Usually I don’t share things that Cannot Be Used Yet, but this one got me really excited! Starting with a future version of Swift, we won’t have to write self inside closures after capturing it weakly:
swift-evolution/0365-implicit-self-weak-capture.md · apple/swift-evolution · GitHub
The background modifier
In the past year the family of .background(...) modifiers has evolved. Now it has a few versions, allowing to customise alignment, safe area ignoring behaviour, and shape style of the background. There’s even a version without any parameters at all - it sets the background to a color fitting the current color scheme. All versions are listed here and are documented pretty well.
Tyler Hillsman
Today I learned about .background()'s ignoresSafeAreaEdges optional parameter. Which means I can make this kind of view I've made a million times, without making this component's parent have .edgesIgnoringSafeArea. https://t.co/2UgxpV4hFB
Testing the mocks
Stumbled onto a peculiar use-case for unit tests, and I’ve never seen it in real-life projects. Documenting mock behaviour via tests will often be seen as “too much”, but it can come handy in cases when lots of tests rely on one mock.
I’m watching WWDC videos from 2021. According to the Apple engineer in the video, this is how to test async code.

I don’t understand this code. What is the value of testing a *mock*ViewModel?

Can someone enlighten me? https://t.co/SRmaWhNlnu
Marina Gornostaeva ✨
@dasdom The test class is called MockViewModelSpec - this test verifies (documents) that the mocked value is 40x40.
It’s useful when another real test fails with “size 40 != 50”: is the value of 40 wrong or did someone just change the mocked value and now all checks relying on it fail?
Thread safety in Swift
A longer but worthy read about different ways to manage multithreading in Swift and their trade-offs.
Thread Safety in Swift
Starting with open source
If you want to contribute to a project but didn’t know which one, here’s a good collection:
Marco Eidinger 🧑🏻‍💻
Do you wanna contribute to open-source Swift projects?

I scanned 91 GitHub repositories.

151 issues were labeled with "Help Wanted".

Here are the 22 issues created within the last twelve months. ⬇️
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 🙌
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.

For feedback or sponsorship ->> [email protected]

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.