@@ -17,6 +17,9 @@ public final class LMViewModel: ILocationManagerViewModel{
1717
1818 // MARK: - Public
1919
20+ /// Strategy for publishing locations Default value is .keepAll
21+ public let strategy : Strategy
22+
2023 /// List of locations Subscribe different Views to locations publisher to feed them
2124 /// or create a proxy to manipulate with the flow like filtering, dropping, mapping etc
2225 @MainActor @Published public private( set) var locations : [ CLLocation ] = [ ]
@@ -37,15 +40,20 @@ public final class LMViewModel: ILocationManagerViewModel{
3740 // MARK: - Life circle
3841
3942 /// - Parameters:
43+ /// - strategy: Strategy for publishing locations Default value is .keepAll
4044 /// - accuracy: The accuracy of a geographical coordinate.
4145 /// - activityType: Constants indicating the type of activity associated with location updates.
4246 /// - distanceFilter: A distance in meters from an existing location.
4347 /// - backgroundUpdates: A Boolean value that indicates whether the app receives location updates when running in the background
44- public init ( accuracy : CLLocationAccuracy ? = nil ,
48+ public init (
49+ strategy : Strategy = . keepLast,
50+ accuracy : CLLocationAccuracy ? = nil ,
4551 activityType: CLActivityType ? = nil ,
4652 distanceFilter: CLLocationDistance ? = nil ,
4753 backgroundUpdates : Bool = false ) {
4854
55+ self . strategy = strategy
56+
4957 manager = . init( accuracy, activityType, distanceFilter, backgroundUpdates)
5058 }
5159
@@ -96,7 +104,11 @@ public final class LMViewModel: ILocationManagerViewModel{
96104 /// - Parameter coordinate: data
97105 @MainActor
98106 private func add( _ coordinate : CLLocation ) {
99- locations. append ( coordinate)
107+ if strategy. isKeepAll || locations. isEmpty{
108+ locations. append ( coordinate)
109+ } else if strategy. isKeepLast{
110+ locations [ 0 ] = coordinate
111+ }
100112 }
101113
102114 /// Set state
0 commit comments