ios - How to pause the application till the json data is downloaded using Alamofire? -


i trying build app using alamofire make request 3 rd party api. 1 of text fields needs show value response.

i have function takes response json , returns value needs shown in textfield. how can delay textfield function, until value response.

and can show progress bar or activity monitor while data being downloaded make sure user not think app doing nothing ?(during api being called , function being executed)

you have number of options:

  1. use activity indicator suggested in comments question.
  2. use completion handler call

    func gettextfielddata(url: string, completion:(string) -> void){ alamofire.request(.post, "http://someurl.com/gettextfielddata", parameters: ["queryvalue": username,], encoding:.json).responsejson { request, response, result in switch result { case .success(let json): let fieldvalue = string(data: json.datausingencoding(nsutf8stringencoding)!, encoding: nsutf8stringencoding)! completion(fieldvalue)

                case .failure(let data, _):                 if let errordata = data, fieldvalue = string(data: errordata, encoding: nsutf8stringencoding) {                     completion(fieldvalue)                 }             }     } } 

    you can update value in completion handler

  3. fetch text field value before present view.

  4. use default value , update when api call returns data.

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -