Skip to content

Instantly share code, notes, and snippets.

@romyilano
Created January 23, 2024 22:41
Show Gist options
  • Save romyilano/021a4c74446a73a8b49b6fc6440fdb11 to your computer and use it in GitHub Desktop.
Save romyilano/021a4c74446a73a8b49b6fc6440fdb11 to your computer and use it in GitHub Desktop.
ways of doing core location in the different async frameworks
// super rusty on combine
// https://brightdigit.com/tutorials/combine-corelocation-publishers-delegates/
class CLLocationManagerPublicist: NSObject, CLLocationManagerCombineDelegate {
...
let locationSubject = PassthroughSubject<[CLLocation], Never>()
func locationPublisher() -> AnyPublisher<[CLLocation], Never> {
return locationSubject.eraseToAnyPublisher()
}
func locationManager(_: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
locationSubject.send(locations)
}
...
}
func authorizationPublisher() -> AnyPublisher<CLAuthorizationStatus, Never> {
return Just(CLLocationManager.authorizationStatus())
.merge(with:
authorizationSubject.compactMap { $0 }
).eraseToAnyPublisher()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment