4 min read

Issue #43

Hi there, welcome to the 43rd issue and happy valentines day 💌
Enjoy the reading!

💎 Sponsor of the week - RevenueCat 💎

In-app subscriptions are a pain to implement, hard to test, and full of edge cases. RevenueCat makes it simple by providing a backend and a wrapper around Apple's StoreKit and Google Play Billing. Get started for free.

Learn more

Documenting hacks

How often do you add dispatch.async as a way to fix a bug? Hopefully not often! The core of solving a bug without causing more bugs, is understanding the root cause and fixing that.
But sometimes, even though we find the root cause, there's no way to address it, so a hacky workaround is necessary. In that case, make sure to add a detailed comment next to the hack. For your colleagues and your future self!

Two ways to mock in tests

Here's Manuel describing two ways to implement a loading view model and its tests. One employs protocols for dependency injecion, and another uses closures. The same example code is used in both approaches, so you can easily compare and pick your favorite. Beautiful and concise articles, with links to GitHub included.

Enhancing Testability with protocols
In the last post we’ve discussed hot to enhance testability without using protocols. In this one, we will build something similar but using protocols instead. We will be using dependency injection to be able to inject the real objects in the app, and inject mock objects in the tests / previews. We w…
Enhancing Testability without protocols
We have all used protocols to enhance testability in our apps, but that can become too verbose, and add extra layers of abstractions to the code. Here is a different approach, without using protocols, that can achieve the same results with way less code. Let’s say we have a screen with a button that…

Don't subclass URLCache

Few days ago I saw a post by Nikita on Mastodon asking if anyone could help him solve a bug with his URLCache subclass not actually caching anything. Some days later, he wrote a post with his findings.
Turns out, nowadays URLCache is not subclassable anymore, even though the documentation states that it is. Instead, we should build our custom caching logic above the url loading layer.

A path of pain with URLCache eviction and subclassing
URLCache class implements the caching of responses to URL load requests, by mapping NSURLRequest objects to CachedURLResponse objects. It provides a composite in-memory and on-disk cache, and lets you manipulate the sizes of both the in-memory and on-disk portions. You can also control the path wher…

What's new in Swift - a refresher

Sometimes when new stuff is released in Swift or the SDK, it gets forgotten because you can't use it right away. Swift versions is one of those things - they are released even before Xcode is.
So here's a refresher on the lovely Swift features we can now introduce in our projects on Xcode 14+ - the shorthand if let, new regex syntax, and more. Available in video and article format:

Discover some New Features of Swift 5.7 — Swift with Vincent
You’re more of a video kind of person? I’ve got you covered! Here’s a video with the same content than this article 🍿

Merge when ready on GitHub

Are you working in a repo where you have to wait for CI to finish before merging a pull request? Then GitHub's new merge queues feature is going to improve your day-to-day :)

Before merge queues, developers were often required to update their pull request branches prior to merging to ensure their changes wouldn't break the main branch when merged. Each update resulted in a fresh round of continuous integration (CI) checks that would have to finish before the developer could attempt to merge. If another pull request got merged, every developer would have to go through the process again.

Even if you're not needing the queue part, the "Merge when ready" button is the feature I've been missing all along.

Pull request merge queue (public beta) | GitHub Changelog
Pull request merge queue (public beta)

Alright, that's it for today! Thank you to RevenueCat for sponsoring this issue ❤️
I'm curious if you found one of the tips particularly interesting - let me know by replying to this email!