Skip to content

Commit bf1749f

Browse files
committed
update
1 parent f477d0b commit bf1749f

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

Sources/d3-async-location/LocationManagerAsync.swift

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ import CoreLocation
1010
///Location manager streaming data asynchronously via instance of ``AsyncStream`` returning from ``start``
1111
@available(iOS 15.0, *)
1212
public final class LocationManagerAsync: NSObject, ILocationManagerAsync{
13-
13+
14+
private typealias StreamType = AsyncStream<CLLocation>.Continuation
15+
16+
// MARK: - Private properties
17+
18+
/// Async stream of locations
1419
private var locations : AsyncStream<CLLocation>{
1520
.init(CLLocation.self) { continuation in
1621
streaming(with: continuation)
1722
}
1823
}
19-
20-
private typealias StreamType = AsyncStream<CLLocation>.Continuation
21-
24+
2225
/// Continuation asynchronously passing location data
2326
private var stream: StreamType?{
2427
didSet {
@@ -42,6 +45,9 @@ public final class LocationManagerAsync: NSObject, ILocationManagerAsync{
4245

4346
// MARK: - Life circle
4447

48+
/// - Parameters:
49+
/// - accuracy: The accuracy of a geographical coordinate.
50+
/// - backgroundUpdates: A Boolean value that indicates whether the app receives location updates when running in the background
4551
public convenience init(_ accuracy : CLLocationAccuracy?,
4652
_ backgroundUpdates : Bool = false){
4753

@@ -65,7 +71,7 @@ public final class LocationManagerAsync: NSObject, ILocationManagerAsync{
6571
/// Check status and get stream of async data
6672
public var start : AsyncStream<CLLocation>{
6773
get async throws {
68-
if await getStatus{
74+
if await getPermission{
6975
return locations
7076
}
7177
throw LocationManagerErrors.accessIsNotAuthorized
@@ -80,8 +86,8 @@ public final class LocationManagerAsync: NSObject, ILocationManagerAsync{
8086

8187
// MARK: - Private
8288

83-
/// Get status
84-
private var getStatus: Bool{
89+
/// Get status asynchronously and check is it authorized to start getting the stream of locations
90+
private var getPermission: Bool{
8591
get async{
8692
let status = await requestPermission()
8793
return isAuthorized(status)
@@ -124,7 +130,7 @@ public final class LocationManagerAsync: NSObject, ILocationManagerAsync{
124130
stream?.yield(location)
125131
}
126132

127-
/// check permission status
133+
/// Check permission status
128134
/// - Parameter status: Status for checking
129135
/// - Returns: Return `True` if is allowed
130136
private func isAuthorized(_ status : CLAuthorizationStatus) -> Bool{

Sources/d3-async-location/viewmodel/LMViewModel.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ public final class LMViewModel: ILocationManagerViewModel{
2424

2525
// MARK: - Life circle
2626

27+
/// - Parameters:
28+
/// - accuracy: The accuracy of a geographical coordinate.
29+
/// - backgroundUpdates: A Boolean value that indicates whether the app receives location updates when running in the background
2730
public init(accuracy : CLLocationAccuracy? = nil, backgroundUpdates : Bool = false){
2831
manager = LocationManagerAsync(accuracy, backgroundUpdates)
29-
3032
}
3133

3234
deinit{
@@ -40,7 +42,7 @@ public final class LMViewModel: ILocationManagerViewModel{
4042
/// Start streaming locations
4143
public func start() async throws{
4244
for await coordinate in try await manager.start{
43-
await update(coordinate: coordinate)
45+
await add(coordinate)
4446
}
4547
}
4648

@@ -53,7 +55,7 @@ public final class LMViewModel: ILocationManagerViewModel{
5355

5456

5557
@MainActor
56-
private func update(coordinate : CLLocation) {
58+
private func add(_ coordinate : CLLocation) {
5759
locations.append(coordinate)
5860
}
5961

0 commit comments

Comments
 (0)