Friday, November 6, 2026
HomeiOS Developmentios - Swift Concurrency: Conforming a third social gathering library to actor...

ios – Swift Concurrency: Conforming a third social gathering library to actor isolation

[ad_1]

I’m within the means of changing some code bases over to utilizing Swift concurrency and am operating into just a few snags alongside the best way.

The present mission I am working by has just a few third social gathering libraries that it depends on, and in a kind of libraries, there’s a delegate protocol that requires some knowledge values to be returned from its strategies.

Right here is an instance of the kind of delegate strategies within the library:

public protocol FooDelegate: AnyObject {
    func foo() -> CGFloat
}

I am trying to return some values from the implementation of the protocol like this:

extension ViewController: FooDelegate {
    func foo() -> CGFloat { // <- Can't fulfill requirement from protocol
        view.bounds.top
    }
}

With none modification, the above is implicitly remoted to the MainActor and can’t fulfill the requirement from the FooDelegate protocol.

One answer I’ve tried was to mark the perform implementation with nonisolated:

extension ViewController: FooDelegate {
    nonisolated func foo() -> CGFloat {
        view.bounds.top // <- Can't be referenced from a non-isolated context
    }
}

This didn’t work although as a result of it references the view controller’s view. That leads to the view being referenced from a non-isolated synchronous context. (There are additionally just a few different points with this since any values which can be handed by into any of the delegate capabilities want to adapt to Sendable to have the ability to be handed throughout actors).

My query is, is there a solution to take a third social gathering library and lengthen it someway in order that it conforms to correct actor isolation with out having to switch its supply code?

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments