refactor: Add extension to Dictionary to simplify values retrieve

This commit is contained in:
Andrea Busi
2021-03-27 17:49:47 +01:00
parent f437c3cde6
commit 5dc64c4f77
3 changed files with 38 additions and 6 deletions
@@ -62,10 +62,7 @@ class AlertsSeismicNotificationExpandedTableViewCell: EQNBaseTableViewCell, MKMa
let aps = notification["aps"] as? [String: Any],
let alert = aps["alert"] as? [String: Any] else { return }
var intensity = -1
if let intensityString = notification["intensity"] as? String, let anIntensity = Int(intensityString) {
intensity = anIntensity
}
let intensity = notification.eqn_intValue(for: "intensity") ?? 0
containerView.backgroundColor = color(for: intensity)
if let title = alert["loc-key"] as? String, let args = alert["loc-args"] as? [String], let arg = args.first {
@@ -74,8 +71,8 @@ class AlertsSeismicNotificationExpandedTableViewCell: EQNBaseTableViewCell, MKMa
// get coordinate
var coordinate: CLLocation?
if let latitudeString = notification["latitude"] as? String, let latitude = Double(latitudeString),
let longitudeString = notification["longitude"] as? String, let longitude = Double(longitudeString) {
if let latitude = notification.eqn_doubleValue(for: "latitude"),
let longitude = notification.eqn_doubleValue(for: "longitude") {
coordinate = CLLocation(latitude: latitude, longitude: longitude)
}