ios - Swift 2 error, converting to JSON -
ive been having error swift 2, simple cant it
here's code before started updating swift 2:
func updateweatherinfo(latitude: cllocationdegrees, longitude: cllocationdegrees) { let url = "http://api.openweathermap.org/data/2.5/forecast" let params = ["lat":latitude, "lon":longitude] println(params) alamofire.request(.get, url, parameters: params) .responsejson { (request, response, json, error) in if(error != nil) { println("error: \(error)") println(request) println(response) self.loading.text = "internet appears down!" } else { println("success: \(url)") println(request) var json = json(json!) self.updateuisuccess(json) } } } here's line throwing error:
let json = json(json) here's whole func after started
func updateweatherinfo(latitude: cllocationdegrees, longitude: cllocationdegrees) { let url = "http://api.openweathermap.org/data/2.5/forecast" let params = ["lat":latitude, "lon":longitude] print(params) alamofire.request(.get, url, parameters: params) .responsejson { (request, response, json) in print("success: \(url)") print(request) let json = json(json) self.updateuisuccess(json!) } } updateuisuccess requires json value, @ moment have (request )
after suggestion tried this:
.success(let data): let data_ar = data as! json // or nsdictionary or nsstring self.updateuisuccess(data_ar) case .failure(let data, let error): print("request failed error: \(error)") } but app crashes @ let data_ar = data as! json // or nsdictionary or nsstring
the variable json looks enum value. try this:
switch json { case .success(let data): let data_ar = data as! nsarray // or nsdictionary or nsstring case .failure(let data, let error): print("request failed error: \(error)") } 
Comments
Post a Comment