ios - Store completion value to an outside variable -


as title suggest. want store/put result of api call via datatask in model or dictionary can access in viewdidload()

class viewcontroller: uiviewcontroller, cllocationmanagerdelegate {  var dict = [[string:any]]() let manager = cllocationmanager() override func viewdidload() {   if(cllocationmanager.locationservicesenabled())    {     switch(cllocationmanager.authorizationstatus()){     case .notdetermined, .restricted, .denied:         print ("")     case .authorizedalways, .authorizedwheninuse:         manager.delegate = self         manager.desiredaccuracy = kcllocationaccuracybest         manager.requestwheninuseauthorization()         manager.requestlocation() // locationmanager function      }      }     }  func locationmanager(_ manager: cllocationmanager, didupdatelocations locations: [cllocation]) {     var lat:string = ""     var long:string = ""     if let location = locations.first{         lat = string(location.coordinate.latitude)         long = string(location.coordinate.longitude)          getapi(lat: lat, long: long, completion: { data in            self.dict = data // tested , returns data         })      }  }   func getapi(lat:string,long:string, completion: @escaping ([[string:any]]) -> void){    //my datatask code here   } } 

the variable has value within locationmanager function due self. unable pass value in variable outside closure block

how can access variable data in getapi closure globally? or pass down variable can accessed in locationmanager


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -