In the shareLocation
method, we call withCheckedThrowingContinuation
method whose closure weakly references self
. What is the purpose of weakly capturing self
in this closure if the manager
is captured strongly?
func shareLocation() async throws {
let location: CLLocation = try await
withCheckedThrowingContinuation { [weak self] continuation in // <- Why weak self?
self?.delegate = ChatLocationDelegate(manager: manager, continuation: continuation)
if manager.authorizationStatus == .authorizedWhenInUse {
manager.startUpdatingLocation()
}
}
...
}
Xcode 14.3.1 also pays attention to this and displays a warning message
Reference to property ‘manager’ in closure requires explicit use of ‘self’ to make capture semantics explicit; this is an error in Swift 6