It's Just Text Files, People

Structured Concurrency Conversion (Part 2)

Alright, in part 1, I laid out the code structure is for Apple’s Async Image Loading sample code. In this session, we’ll update the settings of the project.

Updating the Project

First thing is that we want not capture self in closures, add func urlProtocol(_ protocol: URLProtocol, didReceive response: URLResponse, cacheStoragePolicy policy: URLCache.StoragePolicy), modernize the Xcode project settings, and, most importantly, turn on Swift 6 and Strict Concurrency Checking to Complete.

Xcode Project Settings

We also want to bump the minimum deployment target to iOS 18.0.

Two Bugs

[weak self]

When using completion closures and classes, it important to make sure you’re not capturing a reference to self in the closure in case the closure is never called which would cause the strong reference to self to never be released.

Apple does this in a could places and it’s important to fix those even though we’ll probably replacing the closures with async/await variants.

URLProtocol Did Receive Response

For some reason, when using Apple’s code this does not crash but when changing to an Actor later, it does crash.

The documentation is sparse and gives no indication what might be required. There is this ancient code sample but it says that the authentication calls are also required but I’m not seeing that. but Stack Overflow comes to the rescue.

Well, let’s fix that here.

Ready to Go

With those changes done, we are ready to make our modern changes so look for that in part 3 and 4.