Main actor-isolated instance method 'locationManagerDidChangeAuthorization' cannot be used to satisfy nonisolated protocol requirement

I'm going through the migration to Swift 6 and I am running up with a few things. I have two view controllers which conform to the CLLocationManagerDelegate protocol. Both methods of the delegate have the same issue in my code. Below is an example of the warning received.

Main actor-isolated instance method 'locationManagerDidChangeAuthorization' cannot be used to satisfy nonisolated protocol requirement; this is an error in the Swift 6 language mode

Answered by DTS Engineer in 797649022
I've fixed this by setting the delegate methods to nonisolated

That’s one option, but it may not be the best option. This came up in another context recently, so I decided to write up my own thoughts on it. See Implementing a Main Actor Protocol That’s Not @MainActor.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer

I've fixed this by setting the delegate methods to nonisolated and calling functions within a Task to set the values that need to be set.

I've fixed this by setting the delegate methods to nonisolated

That’s one option, but it may not be the best option. This came up in another context recently, so I decided to write up my own thoughts on it. See Implementing a Main Actor Protocol That’s Not @MainActor.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

@DTS Engineer, here's an example of what I did.

nonisolated func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    Task {
        await changeMyLocation(locations)
    }
}
    
func changeMyLocation(_ locations: [CLLocation]) {
    myLocation = locations.last
}

I created a function to change the location and called it via a task.

I've changed to using @precurrency given your write up.

Main actor-isolated instance method 'locationManagerDidChangeAuthorization' cannot be used to satisfy nonisolated protocol requirement
 
 
Q