Commit e6ea1f92 by Dmitriy Stepanets

Demid's changes

parent 067721e2
...@@ -43,19 +43,22 @@ public class LocationManager { ...@@ -43,19 +43,22 @@ public class LocationManager {
if let selectedIndex = self.selectedLocationIndex, selectedIndex >= newValue.count { if let selectedIndex = self.selectedLocationIndex, selectedIndex >= newValue.count {
self.selectedLocationIndex = newValue.count > 0 ? 0 : nil self.selectedLocationIndex = newValue.count > 0 ? 0 : nil
} }
else {
self.delegates.invoke { (delegate) in
delegate.locationManager(self, changedSelectedLocation: self.selectedLocation)
}
}
self.delegates.invoke { [weak self] (delegate) in self.delegates.invoke { [weak self] (delegate) in
guard let self = self else { return } guard let self = self else { return }
delegate.locationManager(self, updatedLocationsList: self.locations) delegate.locationManager(self, updatedLocationsList: self.locations)
} }
} }
} }
} }
private var selectedLocationIndex: Int? { private var selectedLocationIndex: Int? {
didSet { didSet {
guard selectedLocationIndex != oldValue else {
return
}
var oldLocation: Location? var oldLocation: Location?
if let oldValue = oldValue, oldValue < locations.count { if let oldValue = oldValue, oldValue < locations.count {
oldLocation = locations[oldValue] oldLocation = locations[oldValue]
...@@ -149,7 +152,10 @@ public class LocationManager { ...@@ -149,7 +152,10 @@ public class LocationManager {
} }
DispatchQueue.main.async { DispatchQueue.main.async {
self.selectedLocation = updatedLocation if let indexToUpdate = self.locations.firstIndex(where: { $0 == updatedLocation }) {
self.locations[indexToUpdate] = updatedLocation
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment