I'd like to use a String value without the optional extension. I parse this data from firebase using the following code:
Database.database().reference(withPath:
"Locations").child("Cities").observe(.value, with: { (snapShot) in
if snapShot.exists() {
let array:NSArray = snapShot.children.allObjects as NSArray
for child in array {
let snap = child as! DataSnapshot
let cityName = snap.key
let cityNameString = "(cityName)"
if snap.value is NSDictionary {
let data:NSDictionary = snap.value as! NSDictionary
let lat = data.value(forKey: "lat")
let lng = data.value(forKey: "lng")
let radius = data.value(forKey: "radius")
let latstring = "(lat)"
let lngstring = "(lng)"
let radiusstring = "(radius)"
let city = CityObject(name: cityNameString , lat: latstring , lng: lngstring, radius: radiusstring)
print("Value is", laststring)
self.selectCity(cityObject: city)
}
}
}
})
after parsing this data i try to print e.g. the latstring and get following outpup:
Value is Optional(52.523553)
my CityObject looks like the following:
class CityObject{
var name: String?
var lat: String?
var lng: String?
var radius: String?
init(name: String?, lat: String?, lng: String?, radius: String?){
self.name = name
self.lat = lat
self.lng = lng
self.radius = radius
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…