Reputation:
in the code below its giving a warning the longitude and latitude after the else statement was never used, if my dictionary doesn't contain a value for longitude and latitude will they be set as let longitude = Double(151.209900) and let latitude = Double(-33.865143) ? or am i doing something wrong with the guard let statement
guard let dictionary = snapshot.value as? [String : AnyObject] else { return }
guard let latitude = dictionary["Latitude"] as? String else {
let latitude = Double(-33.865143)
return
}
guard let longitude = dictionary["Longitude"] as? String else {
let longitude = Double(151.209900)
return
}
guard let latDouble = Double(latitude) else { return }
guard let longDouble = Double(longitude) else { return }
Upvotes: 0
Views: 139
Reputation: 32066
The values set for latitude and longitude will never be used because their scope is limited to the guard
I'd probably do it like this instead:
guard let dictionary = snapshot.value as? [String : AnyObject] else { return }
let latitude = Double(dictionary["Latitude"] as? String ?? "-33.865143")
let longitude = Double(dictionary["Longitude"] as? String ?? "151.209900")
Upvotes: 3