ios - start something after PFQuery is finished -


is there possibility after query done? have pfquery queries objects, objectids of these objects apendet array. materuserobjects pfuser, matesidsandnames dictionary, rest string `func querynow(){

    if mateuserobject.isempty == false{          mateid in mateuserobject{                let date = nsdate()             let dateint = date.timeintervalsince1970              let query = pfquery(classname: "calendarevents")             query.wherekey("createdby", equalto: mateid)             query.wherekey("startdate", lessthan: dateint)             query.wherekey("enddate", greaterthan: dateint)             query.cachepolicy = .networkonly             query.findobjectsinbackgroundwithblock({ (objects:[pfobject]?, error:nserror?) -> void in                  if error != nil{                     print(error)                 }else{                      if objects?.isempty == true{                         self.freemateids.append(mateid.objectid!)                         print(self.freemateids)                         if self.mateuserobject.last == mateid{                               if self.freemateids.isempty == false{                                   freemate in self.freemateids{                                      let onefreemate = self.matesidsandnames[freemate]                                     self.freematenames.append(onefreemate!)                                     print(self.freematenames)                                 }                              }                             self.matestableview.reloaddata()                          }                      }                  }               })            }       }   }` 

do use query.findobjectinbackgroundwithblock? if yes suggest use competition handler:

typealias completionhandler = (success: bool) -> void  //  ajoute dans le tableau _applications les applications stockées sur parse func fetchdata(completionhandler: completionhandler) {     let query = pfquery(classname: "test")     var supposeobjectcount: int = 0     var objectcount: int  = 0      //  ajoute un filtre pour la requete     query.orderbyascending("id")      //  trouve les objets sur parse     query.findobjectsinbackgroundwithblock { (objects: [pfobject]?, error: nserror?) -> void in          //  s'il n'y pas d'erreur         if error == nil {              supposeobjectcount = objects!.count               if let objects = objects {                   object in objects {                      // ..                      if(supposeobjectcount == ++objectcount) {                         completionhandler(success: true)                     }                 }              }         }          else {             print("error")         }     } }    //  call function  func test() {     fetchdata({ (success) -> void in           if success {             //  executed when query completed         }     }) } 

hope help!


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -