Issue #28
Hi there,
I hope you find something useful or interesting in today's collection ✨
Live-updating cells
Starting with iOS 15, there's a set of reconfigure
methods that let you update a cell that's already on-screen. This allows us to make nice animations to views inside cells, which are not possible with reloadData
- as it recreates cells from scratch.
In earlier iOS versions it was also possible to update existing cells, by getting on-screen cells with UITableView.cellForRow(at:)
and updating the state manually. reconfigure
can do that with less friction, and it can also update the height of the cell.
Check out Tyler's thread for a deeper dive into the new methods:
Approaches to mocking
Using the factory pattern is a common approach to mocking, but with Swift there are simpler approaches that work just as well: such as injecting values, injecting behaviour as closures (as opposed to injecting instances that perform a behaviour), or having factory methods as closures (as opposed to factory classes). In this thread Nick goes into different ways one can mock behaviour or values:
TL;DR:
On code readability
One comment from Nick's thread stood out to me - it really highlights the two extremes of code architecture: "hardcode everything" => no flexibility, changing one thing breaks other places; vs "mock everything" = code is not discoverable, no transparency in what to change code to achieve the goal. Balance is somewhere in the middle.
Technical debt is debt
Sometimes we say "there should be no technical debt". It's a really good aspiration, we've all been there. But as in life, going into debt can be beneficial:
but also:
Testing Codable initializers
A well-structured and understandable article on unit-testing custom Codable initializers. Lots of little gems in there - for one, the Difference library looks like a huge quality-of-life improvements for unit tests.
How to test custom Codable initializer | Danijela's blog
Sometimes, when parsing a JSON, you need to implement a custom Codable initializer. Because of that custom logic, you're no longer using the default implementation. It's a good idea to test your code.
🤘☮️
Alright, that’s it for today.
Did you enjoy this issue? Let me know by pressing the buttons below. If you enjoyed it, you can help grow the newsletter by spreading the word ☺️
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 🙌
Member discussion