Modern Concurrency: Beyond the Basics, Episode 7: Wrapping Delegate With Continuation | Kodeco


This is a companion discussion topic for the original entry at https://www.kodeco.com/32059632-modern-concurrency-beyond-the-basics/lessons/7

Problem: locationManagerDidChangeAuthorization(:) is not getting called back.

Device: M2 Macbook Air, Xcode 15.2, Ventura 13.6

Issue: As mentioned in the problem, I also tried opening the final project as-is provided in the course material. The manager never called back locationManagerDidChangeAuthorization. After a little digging I found on Apple’s Documentation:

Core Location calls the methods of your delegate object using the RunLoop of the thread on which you initialized the CLLocationManager object. That thread must itself have an active RunLoop, like the one found in your app’s main thread.

What Fixed it – Not Ideal
I tried changing the shareLocation function (It’s wrong) just for the heck of it:

func shareLocation() async throws {
let location: CLLocation =
 try   await  withCheckedThrowingContinuation { [ weak   self ] continuation  in 
DispatchQueue.main.async {
 self ?.delegate = ChatLocationDelegate(continuation: continuation)
}
}
print(location.description)
}

I did get the call back from CLLocation manager. I am not sure if this is the exact problem (with the same thread not being available. FYI I saw the CLLocation manager was created on a global queue with user-initiated qos in debugger). I was able to reproduce this issue 10/10 times so thought of reporting it in case anybody else is running into the same issue.

1 Like

hi Srinath/Sammy, thanks for digging into this! you probably didn’t see my post in the next episode’s forum — Marin updated the book’s code for ChatLocationDelegate to initialise it with the CLLocationManager.