ios - Object added in Parse several times after checking for all non similar objects: -


i querying objects parse, append array. check if array contains particular object, if not, wish add particular object parse. however, each different object in array, , therefore in parse, particular object gets added. instance, if have 4 different objects, object in question added 4 times. see code below:

      @ibaction func nextweek(sender: anyobject) {      self.view.layoutifneeded()      uiview.animatewithduration(0.5, animations: {         self.viewheight.constant = 93         self.view.layoutifneeded() }, completion: nil)      var array2 = [string]()      var query1 = pfquery(classname: "sendmessage")     query1.wherekey("messagesent", equalto:pfuser.currentuser()!.username!)     query1.wherekey("messagereceived", equalto:self.namelabel.text!)     query1.findobjectsinbackgroundwithblock { (objects1, nserror) -> void in          if let objects1 = objects1 as? [pfobject] {                  object1 in objects1 {                      if object1["message"] != nil {                          var textmessage3: string = object1["message"] as! string                          var message3 = message(sender: pfuser.currentuser()!.username!, message: textmessage3, time: nsdate())                          array2.append(message3.message)                   if contains(array2, self.nextweekbuttonl.titlelabel!.text!) {                          } else {                        println(array2)                              println("it not contain")                              var heymessage: pfobject = pfobject(classname: "sendmessage")                             heymessage["messagesent"] = pfuser.currentuser()?.username                             heymessage["messagereceived"] = self.namelabel.text                             heymessage.setobject(self.nextweekbuttonl.titlelabel!.text!, forkey: "message")                              heymessage.save()                      var message = message(sender: pfuser.currentuser()!.username!, message: self.nextweekbuttonl.titlelabel!.text!, time: nsdate())                      self.array.append(message)                     self.tableview.reloaddata()                          }  } }   }  } } 

i have tried use dispatch async main queue, different solutions add object parse, "else" after check if array contains, executed many times array not contain.

any idea ?

thanks lot,


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -