Software Dev

Detecting Changes to Network Access on iOS 12+

Holy crap, there’s finally a dedicated iOS API (NWPathMonitor) that detects and monitors network status!

👉 Detecting Internet Access on iOS 12+

We’ve been dealing with or avoiding the problem of network connectivity on iOS apps for years. Now you can monitor the network status with a callback sort of like you would with location or other services. And you can specify wi-fi or cellular.

I’m glad this finally made it to the to of Apple’s backlog! 👍

Software Dev

DI with Interface Builder

In this dated but thorough Objective-C dependency injection article is a reference to a rather old article asserting that Xcode’s Interface Builder is their “favorite di framework of all time”.

👉 Dependency Inversion Principle and iPhone

I keep feeling frustrated by the added complexity and extra code involved in dependency injection. It can make simple code complex very quickly. So I really love the idea here, which is that Xcode is perfect for DI because it lets you literally just wire up things visually with no extra code. It goes on to make the case for using Interface Builder to wire up more than just UI elements and use it for just about anything.

What’s great about it is that it doesn’t just generate a bunch of code, but instead “freeze dries” real objects to be instantiated when the program loads.

This article is so old that the images don’t load, but I love the ideas and the reminder that DI does not have to involve a bunch of extra code. Thanks to iOS Dev Weekly for the initial link. 👆

Software Dev

Decompiling Swift’s “defer” operator

The Swift “defer” operator my not work exactly like you expect. It’s not exactly the last code executed before the function returns. Well, it kind of is. But also not so much. 🤦🏻‍♂️ As this article says, “defer” basically happens at the “ret” in “return”. 🤯

It takes a while to process what’s going on here, so take your time…

https://medium.com/@sergeysmagleev/how-defer-operator-in-swift-actually-works-30dbacb3477b

It’s also fascinating to see how what some very simple Swift code looks like when decompiled. Temporary registers. Global var access. Code injection in all the wrong places. 🤯 I have newfound respect for compiler writers.

And thanks to Sergey Smagleev on Medium for a great deep dive into “defer”.

Whoa, a simple three-liner has turned into this abomination that spans 34 lines of code.