- Using new concurrency swift model around CoreLocation manager
- Customizable in terms of CLLocationManager properties
- Streaming current locations asynchronously
- Support for iOS and watchOS
- Errors handling
@EnvironmentObject var model: LMViewModel
If task will be canceled the streaming stops automatically. I would recomend to use .task modifire it manages cancelation on it's own. If you desided to use Task and keep it in @State don't forget to cancel() when the time has come or it might course memory leaks in some cases
.task{
do{
try await viewModel.start()
}catch{
self.error = error.localizedDescription
}
}
@ViewBuilder
var coordinatesTpl: some View{
List(viewModel.locations, id: \.hash) { location in
Text("\(location.coordinate.longitude), \(location.coordinate.latitude)")
}
}
///Access was denied by user
case accessIsNotAuthorized
/// Attempt to launch streaming while it's been already started
/// Subscribe different Views to LMViewModel.locations publisher to feed them
case streamingProcessHasAlreadyStarted
/// Stream was cancelled
case streamCancelled
/// Unknown termination
case unknownTermination
public protocol ILocationManagerViewModel: ObservableObject{
/// List of locations
@MainActor
var locations : [CLLocation] { get }
/// Start streaming locations
func start() async throws
/// Stop streaming locations
func stop()
}
if you are using the simulator don't forget to simulate locations
Available on watchOs
- You need to have Xcode 13 installed in order to have access to Documentation Compiler (DocC)
- Go to Product > Build Documentation or ββ§β D