Here’s a way you can define helper functions in Swift that are injected into your app at runtime for use whilst debugging — no LLDB-esque Python required!

Image for post
Image for post

Act I — Setting the scene

Let’s say we are debugging an issue where the focused view has gone missing. In other words, we are looking for any UIView instance whose isFocused property is true. In this scenario, it’s helpful to us to set that view’s background color to a red so that we can easily see where it is on the screen. In the past, I have achieved this by creating a function to recurse through all views in the app, setting background colours where appropriate:

1. func highlightFocusedView(in target: UIView) {
2. target.subviews.forEach …

What if you need to fix an issue caused by an iOS version newer than the Xcode version you are using?

With the release of iOS13 imminent, we’ve found some critical issues that can only be fixed by using new APIs only available via Xcode 11. However our project uses Xcode 10 — building from Xcode 11 introduces even more issues. Of course, we will eventually need to move to the newest IDE, but for now we need a low-risk solution.

The Problem

We have a UINavigationBar with the following appearance traits:

Image for post
Image for post

This combination of customization works perfectly on iOS12 and earlier, but on iOS13 the background of the bar appears white (when building from both Xcode 10 and 11).

I recently experienced async/await whilst working in JavaScript. Wouldn’t it be great if we could do the same in Swift!

Image for post
Image for post
Here’s what we are going to achieve today, I wouldn’t actually use a ternary operator like this… I just wanted this snippet to fit nicely as the Medium cover image 😅

URLSession provides an asynchronous interface where a closure is called once the abstracted network call has completed. We’re all familiar with this, and it has encouraged us to write our own network layers in a similar fashion. A typical network call might be defined as:

I left a blank line at the end for those of you whose scroll bars don’t hide automatically

Consider a scenario where you need to make multiple API calls, one after another, such as the following:

After login, request the latest Terms and Conditions. If the User has not already accepted them, show the Terms and Conditions screen. …


Max Chuquimia

Senior Software Engineer, Electronics Enthusiast, Appreciator of Music

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store