CombineLocationManager - swift CLLocationManager
& CLLocationManagerDelegate
exposed as Combine publishers
This package try to solve:
- Avoid system clases that lead to unexpected crashes like
CLBeacon
due to private initializer. - Replace closures with Combine publishers
- Ready to use UseCases (Clean Arhitecture)
- Public interfaces for mocks
- Generic methods & protocols
- Test coverage (partial)
dependencies: [
.package(url: "https://github.com/adriantabirta/CombineLocationManager.git", .branch(from: "main"))
]
- Create own domain model & conform it to already defined protocol, in this case SystemLocation
import CombineLocationManager
struct CoordinateDomainModel: SystemCoordinate {
private(set) var latitude: Double
private(set) var longitude: Double
init() {
latitude = .zero
longitude = .zero
}
init(latitude: Double, longitude: Double) {
self.latitude = latitude
self.longitude = longitude
}
}
struct LocationDomainModel: SystemLocation {
typealias Coordinate = CoordinateDomainModel
var horizontalAccuracy: Double
var direction: Double
var timestamp: Date
var coordinate: SystemCoordinateStub
init() {
self.horizontalAccuracy = .zero
self.direction = .zero
self.timestamp = .init()
self.coordinate = .init()
}
init(coordinate: SystemCoordinateStub, horizontalAccuracy: Double, direction: Double, timestamp: Date) {
self.horizontalAccuracy = horizontalAccuracy
self.direction = direction
self.timestamp = timestamp
self.coordinate = coordinate
}
}
- Use into your domain usecase like:
func locationStream() {
let stream = RealSystemGetLocationsStreamUseCase()
(stream.execute() as AnyPublisher<[LocationDomainModel], Error>)
.map { ... }
.sink({ ... })
.store(in: &cancellables)
}
This repo is in active development state, so feel free to open PR, issues & missing features. Future SPM targets that may be useful:
- LocationManagerAsync - for async await
- LocationManagerRx - for RxSwift