View profile

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

 iOS Code Review
 iOS Code Review
I spent the whole morning thinking about whether it’s appropriate to send out an issue today. For the sake of consistency I decided in favour of delivering on the promise of code improvement tips in your inbox every two weeks.
This time I got no cheerful words though. If you’re able to enjoy something today - I hope you enjoy these tips.

Uninitialized variables + defer = 👯‍♀️
One of my favourite combinations of Swift’s features:
Nuno Vieira
@rudrankriyam The defer statement can be really useful to write safe code 🙂 With the example below we guarantee 2 things. 1 - Any branch of the code must set the `result` variable otherwise the code won't compile. 2 - The completion is always called on the main thread. https://t.co/NYPiQsJL0N
HttpServer or HTTPServer?
Swift API design guidelines have the answer:
Fabian Fett
I don’t know who needs to hear this, but according to the Swift API Design Guidelines uppercased acronyms and initialisms should be uppercased in Swift code as well.

✅ HTMLTag, HTTPServer
❌ HtmlTag, HttpServer

https://t.co/gOtQ3DbJ57 https://t.co/vIw80b0yTY
Representing measurement units
Measurement is a type that represents a numeric quantity labeled with a unit of measure, with support for unit conversion and unit-aware calculations. MeasurementFormatter has a range of options for presenting measurements in a localised way. Both are available since iOS 10. Starting iOS 15, SwiftUI’s Text supports measurement formatting too:
Mark Moeykens
If you display any kind of measurements in your app, you can now use the Measurement object and #SwiftUI's Text view will format it based on its format parameter specification.

(👉 Available in #iOS15 only) https://t.co/RWKjLRCoUE
The missing SwiftUI docs
Community-made documentation for SwiftUI types with beautiful examples. For instance, check out TabView documentation to get a taste.
Is there the best architecture?
What works for a tiny startup won’t work for a mature product with a large dev team, and vice versa. It’s obvious, but still worth remembering when we discuss architectures in abstract.
Rui Peres
Architecture choice is a function of the environment.

- Greenfield vs Brownfield
- Team maturity
- Team size
- Shift in the underlying tech (rx vs combine vs async)
- Time constraints

Rarely it's bound to a company domain/sector. https://t.co/q4gTB97Xq9
☮️
Alright, that’s it for today. 
Wherever you are, I hope you’re safe.
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.