Modern Concurrency: Beyond the Basics, Episode 8: Wrapping Callback 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/8

Hi, running the project from the starting code return SWIFT TASK CONTINUATION MISUSE: shareLocation() leaked its continuation! instead of lat,lng as in your Debug area.
Update: same error at the end of tutorial, deleting app and giving access for location didnโ€™t solve the issue.

Hi Eytan! The note says

At the time of recording, Xcode 14 flags a runtime error in the location delegate continuation. If this happens to you, use Xcode 13 for the rest of Part 1.

This long after recording, itโ€™s probably not easy to get back to Xcode 13. The Modern Concurrency book was updated in Feb 2023, and the code in Chapter 5 has a different location delegate:

class ChatLocationDelegate: NSObject, CLLocationManagerDelegate {
  typealias LocationContinuation = CheckedContinuation<CLLocation, Error>
  private var continuation: LocationContinuation?

  init(manager: CLLocationManager, continuation: LocationContinuation) {
    self.continuation = continuation
    super.init()
    manager.delegate = self
    manager.requestWhenInUseAuthorization()
  }
...

and in BlabberModel:

let location: CLLocation = try await
withCheckedThrowingContinuation { [weak self] continuation in
  self?.delegate = ChatLocationDelegate(manager: manager, continuation: continuation)
  if manager.authorizationStatus == .authorizedWhenInUse {
    manager.startUpdatingLocation()
  }
}

Even this needs further update, as now you need explicit use of self inside the closure.

Hi, itโ€™s November 2024 and this note

At the time of recording, Xcode 14 flags a runtime error in the location delegate continuation. If this happens to you, use Xcode 13 for the rest of Part 1.

still remains the same.

I had only found out about the working code, regardless of the explicit self warning, after digging into the forum. What stops you from updating the course note?