ios - execute function after function is not working swift 3 -


this function want execute after downloading details , function whcih update uielements after downloading. function inside "currentweather.swift"

func downloadweatherdetails(completed: ( () -> () )){     // tell alimofire download     let currentweatherurl = url(string: current_weather_url)!     alamofire.request(currentweatherurl).responsejson{ response in          let result = response.result         if let dict  = result.value as? dictionary<string, anyobject>{              if let name = dict["name"] as? string{                 self._cityname = name.capitalized                 print(self._cityname)             }              if let weather = dict["weather"] as? [dictionary<string, anyobject>]{                 if let main = weather[0]["main"] as? string{                     self._weathertype = main.capitalized                     print(self._weathertype)                 }             }              if let main = dict["main"] as? dictionary<string, anyobject>{                 if let currenttemperature = main["temp"] as? double {                     let kelvintofarenhitepredevision = (currenttemperature * (9/5) - 459.67 )                     let kelvintofarenhite = double(round(10 * kelvintofarenhitepredevision/10))                     self._currenttemp = kelvintofarenhite                     print(self._currenttemp)                 }             }           }       }     completed() } 

}

and function update uiemelents

    func updatemainui(){      datelabel.text = currentweather.date     currenttemplabel.text = "\(currentweather.currenttemp)"     currentweathertypelabel.text = currentweather.weathertype     locationlabel.text = currentweather.cityname     currentweatherimage.image = uiimage(named: currentweather.weathertype) } 

and call them on override func viewdidload()

 override func viewdidload() {     super.viewdidload()     tableview.delegate = self     tableview.datasource = self      currentweather.downloadweatherdetails { () -> () in          self.updatemainui()     } } 

now when executing not updating ui data printing them inside console

can me issue

you calling completed() before request completed.

        completed() //<- need call completion handler inside closure.     }     //completed() //<- called before completion } 

i haven't checked other parts of code, @ least need fix this.


Comments

Popular posts from this blog

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

laravel - Undefined property: Illuminate\Pagination\LengthAwarePaginator::$id (View: F:\project\resources\views\admin\carousels\index.blade.php) -