Hope your Thursday is going the way you want it to go 🌟
Let's dive in right away!
Check your back buttons
Do you remember about this obscure feature added in iOS 14? Holding the back button shows the navigation stack history and lets you navigate to any item. Cool feature, right? Not so fast...
The titles are taken from the back button. If you're still hiding the back button titles by setting
navigationItem.backButtonTitle = "" , you will have this bug, where rows are just empty. I checked some popular apps and many of them have this issue 😵
Since iOS 14, there's a proper way to hide the back button title by using
backButtonDisplayMode. @sarunw wrote a detailed guide on it, make sure to check it out!
PS. if you're on SwiftUI, remember to add the
.navigationTitle(_:) modifier even when you hide the navigation bar on that view.
Apple adds a new way to control where the back button will pick up its title. Let's see how this make thing a lot easier going forward.
On force unwrapping
Yet another debate on force unwrapping happened last week. With usually no end in sight for this polarising topic, we might have found the answer.
I loved this perspective from @johnhaney: both sides of the debate have the same goal - to account for the nil cases. The only difference is that for some, it's to think of it right away, and for others, only to do that if&when the crashes happen in production and become a problem.
Check the whole thread if you want to read other interesting opinions.
Testing throwing code
Test code is also code. @nicklockwood shares three tips for modernizing the implementation of your unit tests with
XCTUnwrap and marking test functions as throwing:
Pro rebase tip
If you're using rebase and are switching branches in the process, this tip will save you a bunch of friction. This is an older tweet, but I regularly meet people who are unaware of this trick, so here it is :)
If you're unsure why one would want to use rebase, I recommend reading the Demystifying Git Rebase article series.
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 🙌