swift - Post rating system in iOS with parse.com - upvote / downvote -


simply: want rating system of post (or image) works same in yik yak or 9gag - user can upvote or downvote once post. dont want store these data on device on parse.com. count comments. ideally in 1 query parse.com

i using code dont think approach how because every image create new query. have 4 tables in parse.com user, image, comment, rating , connected pointers image or user.

func loaddata(){     forpaginationstart = 0     numberofimagesperpage = 5     imagedata.removeallobjects()     var findimagedata: pfquery = pfquery(classname: "image")     findimagedata.wherekey("deleted", equalto: 0)     findimagedata.orderbydescending("createdat")     findimagedata.skip = forpaginationstart     findimagedata.limit = numberofimagesperpage     findimagedata.findobjectsinbackgroundwithblock{         (objects:[anyobject]?, error:nserror?)->void in          if error == nil{             object in objects! {                  let image:pfobject = object as! pfobject                 self.imagedata.addobject(image)                  //comment counts                 var countcomments = pfquery(classname:"comment_image")                 countcomments.wherekey("image_id", equalto: pfobject(withoutdatawithclassname: "image", objectid: "\(image.objectid!)"))                 countcomments.wherekey("deleted", equalto: 0)                 countcomments.countobjectsinbackgroundwithblock {                     (count: int32, error: nserror?) -> void in                     if error == nil {                         println("there \(count) comments image: \((object.objectid!)!)")                         self.commentcount.append(countcomments.countobjects())                     }                 }             }              self.tableview.reloaddata()          }      }      //count number of records in db pagination end     var totalnumofrows: pfquery = pfquery(classname: "image")     totalnumofrows.wherekey("deleted", equalto: 0)     totalnumofrows.countobjectsinbackgroundwithblock {         (count: int32, error: nserror?) -> void in         if (error == nil) {             self.totalnumrecords = int(count)             println("total records: \(self.totalnumrecords)")         }       } } 

i had working php , sql parse same approach doesnt work me... asked db value user, if 1 user upvoted , if negative 1 downvoted, 0 neither 1 , set button according value sql query:

ifnull((select value rating image.id = rating.image_id , rating.user_id = (select id user uuid='$uuid')), 0) userrating 

- (instancetype)wherekey:(nsstring *)key matcheskey:(nsstring *)otherkey inquery:(pfquery *)query 

you can use this method on pfquery, example:

var countcomments = pfquery(classname:"comment_image") var findimagedata: pfquery = pfquery(classname: "image") findimagedata.wherekey("deleted", equalto: 0) findimagedata.orderbydescending("createdat") findimagedata.skip = forpaginationstart findimagedata.limit = numberofimagesperpage countcomments.wherekey("image_id", matcheskey:"objectid", inquery: ) countcomments.wherekey("deleted", equalto: 0) countcomments.countobjectsinbackgroundwithblock {     (count: int32, error: nserror?) -> void in      if error == nil {          println("there \(count) comments images!")      } } 

by setting count query this, don't have call count each image, don't know in background if parse optimizes make faster current query.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -