Skip to content

Commit c5dc87b

Browse files
authored
Merge pull request #27 from AndrewDodd42/fix-desired-accuracy-init
Fix desired accuracy initialiser
2 parents 485a6e1 + 31aca10 commit c5dc87b

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

Sources/AsyncLocationKit/AsyncLocationManager.swift

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,19 @@ public final class AsyncLocationManager {
3535
private var locationManager: CLLocationManager
3636
private var proxyDelegate: AsyncDelegateProxyInterface
3737
private var locationDelegate: CLLocationManagerDelegate
38-
private var desiredAccuracy: LocationAccuracy = .bestAccuracy
3938

40-
public init() {
41-
locationManager = CLLocationManager()
42-
proxyDelegate = AsyncDelegateProxy()
43-
locationDelegate = LocationDelegate(delegateProxy: proxyDelegate)
44-
locationManager.delegate = locationDelegate
45-
locationManager.desiredAccuracy = desiredAccuracy.convertingAccuracy
39+
public convenience init(desiredAccuracy: LocationAccuracy = .bestAccuracy) {
40+
self.init(locationManager: CLLocationManager(), desiredAccuracy: desiredAccuracy)
4641
}
47-
48-
public init(locationManager: CLLocationManager, desiredAccuracy: LocationAccuracy) {
42+
43+
public init(locationManager: CLLocationManager, desiredAccuracy: LocationAccuracy = .bestAccuracy) {
4944
self.locationManager = locationManager
5045
proxyDelegate = AsyncDelegateProxy()
5146
locationDelegate = LocationDelegate(delegateProxy: proxyDelegate)
5247
self.locationManager.delegate = locationDelegate
5348
self.locationManager.desiredAccuracy = desiredAccuracy.convertingAccuracy
5449
}
5550

56-
public convenience init(desiredAccuracy: LocationAccuracy) {
57-
self.init()
58-
self.desiredAccuracy = desiredAccuracy
59-
}
6051

6152
public func getAuthorizationStatus() -> CLAuthorizationStatus {
6253
if #available(iOS 14, *) {

Tests/AsyncLocationKitTests/AsyncLocationKitTests.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,21 @@ import CoreLocation
33
@testable import AsyncLocationKit
44

55
final class AsyncLocationKitTests: XCTestCase {
6-
let locationManager = AsyncLocationManager(locationManager: MockLocationManager(), desiredAccuracy: .bestAccuracy)
6+
static let mockLocationManager = MockLocationManager()
7+
8+
func testDesiredAccuracy() {
9+
let firstAccuracy: LocationAccuracy = .nearestTenMetersAccuracy
10+
let locationManager = AsyncLocationManager(locationManager: AsyncLocationKitTests.mockLocationManager, desiredAccuracy: firstAccuracy)
11+
XCTAssertTrue(AsyncLocationKitTests.mockLocationManager.desiredAccuracy == firstAccuracy.convertingAccuracy)
12+
13+
let secondAccuracy: LocationAccuracy = .bestForNavigationAccuracy
14+
locationManager.updateAccuracy(with: secondAccuracy)
15+
XCTAssertTrue(AsyncLocationKitTests.mockLocationManager.desiredAccuracy == secondAccuracy.convertingAccuracy)
16+
}
717

818
func testRequestLocation() async {
919
do {
20+
let locationManager = AsyncLocationManager(locationManager: AsyncLocationKitTests.mockLocationManager)
1021
let location = try await locationManager.requestLocation()
1122

1223
switch location {

0 commit comments

Comments
 (0)