Me as an illustration

Hi, I’m Iva.

I build apps for iPhone, iPad and Mac, and work on the Nextcloud desktop client. These are my notes.

January 31, 2024 · 1 min read

Nonisolated Extension Functions

With strict concurrency checking enabled in an Xcode project, I encountered a warning while using URLSession.

After a short research I came across this Apple developer forums post which suggest an interesting pattern: extending framework types with nonisolated functions. Reimplementing existing functions with the nonisolated keyword allows calls outside their actor’s isolated domain. This might be an acceptable solution in some use cases where a call is known to not have any side effect on state.

extension URLSession {
    public nonisolated func getData(for url: URL) async throws -> (Data, URLResponse) {
        try await data(from: url)
    }
}