View profile

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

 iOS Code Review
 iOS Code Review
Hi there,
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
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!
Kilo Loco 👨🏽‍💻🥑
Did you know that CLLocationAccuracy is just a typealias for Double and is simply a value for accuracy in meters? You could just set the desired accuracy with a number if you wanted. #SwiftLang https://t.co/rNI6TwrySA
Printing HTTP status codes
Turns out Foundation has a method for producing human-readable strings from HTTP status codes: HTTPURLResponse.localizedString(forStatusCode:)
Toomas Vahter
🎯 Swift/iOS/macOS tip #5: HTTPURLResponse has a function for returning localised strings for HTTP status codes.
#swifttip #xcode #iosdev #macosengineer https://t.co/kNH0hhKYfs
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.
Harty 
Have you ever used GroupBoxes? They are a great and easy design option! https://t.co/AnTkq2lpCH
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 UICollectionViewCompositionalLayout or NSDiffableDataSource*, I recommend checking it out.
Filip Nemecek
Small PSA: If you are working in #UIKit with Collections Views I have this repo with many examples which use Compositional Layout + Diffable Data Sources. Feel free to "borrow" any code 😀 #iOSDev

https://t.co/XHBBOqOGOO
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
Some philosophy
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?
scott belsky
in startup/VC phase, you need one person to say yes. for innovation in big cos, often feels like you need to find nobody that says no.

explains why “ask for forgiveness, not permission” is such a mantra, and why a culture of experimentation + empowerment is so critical.
☃️
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.

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.