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

#19・
1.2K

subscribers

23

issues

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,
The world is still a mess, but I’m really excited to bring you some learnings today. Enjoy! 🙌

The Code Review Pyramid
What to look at in a code review? Check out this infographic shared by @gunnarmorling. Also available on the blog: The Code Review Pyramid
Gunnar Morling 🌍
What to focus on during a code review? Don't waste your time with automatable formalities like code style. Rather spend your review budget on those aspects which will be hard/expensive to change later on. The "Code Review Pyramid" provides some guidance on what to look for. https://t.co/PBRpMwLxlk
Struct properties - var or let?
Found this conversation thread on pros and cons of making properties in structs var vs let. I like the take by @myell0w, and you’ll find even more opinions in the thread.
Michael Brown 🇺🇦
Is there any good reason to use `let` for properties of structs? Using `var` lets you set default values, with `let` you can't do that.
Also, if you use `let` when you use the struct you get immutability anyway🤷‍♀️

#SwiftLang https://t.co/z0vCaUPe0j
Michael Brown 🇺🇦
Just to be clear, mutating a var in a struct is completely equivalent to calling init with different values: https://t.co/8YIJHuZy8A
Matthias Tretter
@mluisbrown depends on the property, sometimes going through the hoops of creating a new variable is a feature rather than a bug. I like to convey intent as much as possible when designing APIs (var = expected to change, let = constant over lifetime)
Decoding corrupted arrays with Codable
By default, decoding an array of Codable will fail if one of the elements fails to decode. That’s not obvious behaviour - and it’s not always desirable.
The common way to solve this is to decode as an array of wrapper objects where the model is optional, and compactMap it after. For concrete implementation details, check out the article:
Decode an array with a corrupted element | Sarunw
Fixing SwiftUI preview pausing
Turns out, structure of the code affects how SwiftUI previews are functioning. For example, changing the default value of a property will pause previews, but if the property is computed - changing the body won’t pause previews.
This is because live reloading is implemented using @_dynamicReplacement attribute, which only supports replacing bodies of functions and properties. If you want to learn even more details, check out this article I wrote 2 months ago and forgot to include earlier 😀
Fixing SwiftUI’s Automatic Preview Updating Paused | Marina Gornostaeva
A refactoring story
An entertaining and educational read about refactoring of a complex app. Good with a cup of tea 🍵
Refactoring Uber's Rider app • Space is Disorienting
☮️
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. Swift, Objective-C, iOS, macOS, SwiftUI, UIKit and more. Curated by Marina Gornostaeva and published every other Thursday.

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.