I'm new to programming for ios so my question may be silly ;-) I'm trying to parse some JSON data. My code look's like:
var task = session.dataTaskWithURL(url!, completionHandler: { (data, response, error) -> Void in
if(error != nil){
println("error")
}else{
var error: NSError?
var wetherData = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &error) as NSMutableDictionary
var wd = wetherData["current_observation"] as NSMutableDictionary
var xd = wd["temp_c"]! as String
println(xd);
}
})
I want xd variable to be a string but while casting i have an error

println(wd["temp_c"]) returns "Optional(4)"
wd["temp_c"] look's like this

var xd = wd["temp_c"]?.toString()this will makexd: String?- JMFRString()constructor.var temp = wd["temp_c"]! as Int; var xd = String(temp)- JMFR