Async location streamer using new concurrency model in Swift


  • Using new concurrency swift model around CoreLocation
  • Streaming current locations asynchronously
  • Customizable in terms of accuracy
  • Errors handling

How to use

1. Add to info the option “Privacy – Location When In Use Usage Description”

Add to info

2. Add or inject LMViewModel into a View

    @EnvironmentObject var model: LMViewModel

3. call ViewModel method start() within async environment of the View

                     try await viewModel.start()
                     self.error = error.localizedDescription

4. Bake into visual presentation async stream of data from “locations” property of the ViewModel

    var coordinatesTpl: some View{
        List(viewModel.locations, id: \.hash) { location in
            Text("\(location.coordinate.longitude), \(location.coordinate.latitude)")

5. Showcase error

    ///Access was denied by  user
    case accessIsNotAuthorized

ViewModel API

public protocol ILocationManagerViewModel: ObservableObject{
    /// List of locations
    var locations : [CLLocation] { get }
    /// Start streaming locations
    func start() async throws
    /// Stop streaming locations
    func stop()

SwiftUI example of using package


if you are using the simulator don’t forget to simulate locations

simulate locations


  • You need to have Xcode 13 installed in order to have access to Documentation Compiler (DocC)
  • Go to Product > Build Documentation or โŒƒโ‡งโŒ˜ D


View Github