Welcome to the 13th issue, the last one for 2021. As a treat, there are a few more tips than usual. Enjoy!
Happy holidays and see you on January 13th! ❄️
Changes to app launch sequence
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 culprit is that some resources such as keychain might not be available, as the device might be still locked. So we shouldn't be initiating any work or for example checking of the API token presence earlier than
application(:didFinishLaunching:...). Check official documentation on this behaviour here: About the App Launch Sequence.
Solving Mysterious Logout Issues on iOS 15 | Source Diving
At Cookpad, after the public launch of iOS 15 we started to receive reports from users telling us that they were being repeatedly logged out when opening our app. This came as quite a surprise since…
Learning from CLLocation APIs
Two learnings here: 1) desired location accuracy in
CoreLocation can be set to a custom value in meters 2) how not to design an API 🤡 Here it's understandable though - this API comes from pre-Swift times and needs to be compatible with Objective-C, so it couldn't be modelled with enums with associated values. Thanks @Kilo_Loco for the find!
Printing HTTP status codes
Turns out Foundation has a method for producing human-readable strings from HTTP status codes:
Easy boxes in SwitUI
GroupBox is a SwiftUI component that replaces the setup with
VStack + padding + mask. GroupBox can be customised with different styles, though there's only one provided out of the box. We can build our own styles, here's a great article on that: Mastering GroupBox in SwiftUI on Swift with Majid.
Common compositional layouts for UICollectionView
Filip has shared an awesome collection of various compositional layouts in his Github repo. If you are looking to start mastering
NSDiffableDataSource*, I recommend checking it out.
Working with arrays in real apps
If you need to take an item from an array, perform an asynchronous operation with it, and update it in the array, how do you do that safely without messing with indexes, which can change in the meantime? That requires some careful code that would need to be unit-tested.
This is a library for working with identifiable objects in collections, making it easy to access elements by identifiers instead of indexes. The readme goes more into the use-cases and problems with access by index.
GitHub - pointfreeco/swift-identified-collections
A library of data structures for working with collections of identifiable elements in an ergonomic, performant way.
Some of you are working in small companies, and some in bigger cos. This tweet isn't really code related, but I feel that it applies to anything. I've never thought of it this way before, but the distinction applies so clearly to all the teams I worked at. Which culture do you want to foster?
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 🙌