ios - Why is the method being run at the end? -


i trying recover animal objects based on parameters. first need retrieve location parse name, since importing more 1 , using geocoder, using strings, , not array. instead of appending imported information array, mutating variable. though happen query go through first object run retrievelocation method, proceed next object imported parse, instead imports runs method, in end 1 object instead of how many supposed imported.

let query = pfquery(classname: "animals")     query.findobjectsinbackgroundwithblock { (objects: [pfobject]?, error: nserror?) in         if(error == nil){             object in objects!{                         if let addressobj = object["add"] as? nsdictionary{                             if let address = addressobj["address"] as? string{                                  self.addr = address                                 print("sdfadsf \(self.addr)")                              }                         }                         if let name = object["name"] as? string{                             self.impname = name                             print("rturrty \(self.impname)")                             self.retrievelocation()                         }                  }            }       } func retrievelocation(){     let geocoder = clgeocoder()          geocoder.geocodeaddressstring(addr, completionhandler: {(placemarks, error) -> void in             if((error) != nil){                 print("error", error)             }             if let placemark = placemarks?.first {                 let coordinates = pfgeopoint(location: placemark.location)                 if(whatever true){                  append name , address array. part repeats of latest  imported object.               }             }          })  } 

this should work if use local variable , pass local variable implementation of retirvelocation takes string paramter retrievelocation(address: string)

let query = pfquery(classname: "animals") query.findobjectsinbackgroundwithblock { (objects: [pfobject]?, error: nserror?) in     if(error == nil){       object in objects!{       if let addressobj = object["add"] as? nsdictionary{         if let address = addressobj["address"] as? string{          let newaddress = address         print("sdfadsf \(self.addr)")          }       }    if let name = object["name"] as? string{      self.impname = name      print("rturrty \(self.impname)")      self.retrievelocation(newadress)     }   }  } }  func retrievelocation(address: string){     let geocoder = clgeocoder()      geocoder.geocodeaddressstring(address, completionhandler: {(placemarks, error) -> void in         if((error) != nil){             print("error", error)         }         if let placemark = placemarks?.first {             let coordinates = pfgeopoint(location: placemark.location)             if(whatever true){                 append name , address array. part repeats of latest  imported object.             }         }      })  } 

problem seems time self.addr being used in geocodeaddresstring method, for-loop has finished , overwritten previous values @ 1 point individually held self.addr. using local variable, sure use unique value geocodeaddressstring each time executed


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -