Created
January 23, 2024 22:41
-
-
Save romyilano/021a4c74446a73a8b49b6fc6440fdb11 to your computer and use it in GitHub Desktop.
ways of doing core location in the different async frameworks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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