From 6672ed8faa15e62f5a2b17cec4baee5a1ac54cd9 Mon Sep 17 00:00:00 2001 From: Gary Tokman Date: Wed, 5 May 2021 23:15:27 -0400 Subject: [PATCH] feat: add docs for CLLocation authorization --- .../CoreLocation/CLLocationManager.swift | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Sources/ExtensionKit/CoreLocation/CLLocationManager.swift b/Sources/ExtensionKit/CoreLocation/CLLocationManager.swift index cb05ebb..51b75be 100644 --- a/Sources/ExtensionKit/CoreLocation/CLLocationManager.swift +++ b/Sources/ExtensionKit/CoreLocation/CLLocationManager.swift @@ -3,6 +3,41 @@ import CoreLocation public extension CLLocationManager { + /* + ``` + class LocationStore: ObservableObject { + + @Published var coordinate: CLLocationCoordinate2D = .zero + @Published var status: CLAuthorizationStatus = .notDetermined + + let manager = CLLocationManager() + + var cancellables = Set() + + func requestPermission() { + CLLocationManager + .requestLocationAuthorization(with: manager, type: .whenInUse) + .assign(to: \.status, on: self) + .store(in: &cancellables) + } + + func getLocation() { + CLLocationManager + .receiveLocationUpdates(from: manager) + .compactMap(\.last) + .map(\.coordinate) + .sink { result in + if case let .failure(error) = result { + dprint("Error: \(error.localizedDescription)") + } + } receiveValue: { coordinate in + self.coordinate = coordinate + } + .store(in: &cancellables) + } + } + ``` + **/ /// Request locaton authorization and subscribe to `CLAuthorizationStatus` updates /// - Parameters: /// - manager: `CLLocationManager`