如何进行“不在"解析查询 [英] How to do a "not in" query in Parse

查看:101
本文介绍了如何进行“不在"解析查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Swift中构建一种热门或不流行的应用程序,用户可以在其中投票:分别在图像上投票HOT,NOT和MAYBE.

I'm building a sort of hot or not style app in Swift where the user can vote: HOT, NOT and MAYBE on an image, respectively.

对于用户每次访问图像时,他们都通过点击IBAction进行投票,这将触发一个查询,该查询显示来自Parse的总投票和总热点的结果,如下面的代码所示.

For every time the user gets to a image, they vote by tapping the IBAction, which triggers a query that shows the result of the total votes and total hots from Parse as shown in my code below.

我计划有1,000张图像.

I plan to have 1,000 images.

我可以预加载与每个图像对应的一些objectID,然后在用户对图像进行投票时,已经从解析中预加载/查询了数据吗?我该怎么办?有人在我之前的问题中建议在Parse中使用NOT IN查询.我该如何在Parse中执行NOT IN查询?我将如何去做?

Can I preload some of the objectIDs that correspond to each respective image, and then when the user votes on the image, the data is already preloaded/queried from parse? How would I go about that? Someone recommended in my previous question to use a NOT IN query in Parse. How do I do a NOT IN query in Parse and how would I go about doing that?

现在,我正在为每个ObjectID编写一个查询,该查询将从1000个不同的图像中进行1000个查询...显然不可缩放.

For now, I'm writing a query for each ObjectID which would take 1000 queries from 1000 different images... Obviously unscalable.

更多代码说明:

swipePosition变量只是一个计数器,用于对用户所在的图像进行计数.正在存储的图像位于Array中,现在存储在Xcode中.如果将它们存储在Parse中,也许还可以预加载它们?

The swipePosition variable is just a counter that counts which image the user is on. The images being stored are in an Array for now stored on Xcode. Maybe they can be preloaded as well if they are stored on Parse?

(我仅显示"hotButtonQuery"功能,但还有一个Not and Maybe buttonQuery函数.)

(I am only showing the "hotButtonQuery" function, but there is also a Not and Maybe buttonQuery function.)

有没有一种方法可以简化此代码,使其具有可伸缩性?因为到目前为止,我无法缩放25张图像.

Is there a way to simply this code so that it's scalable? Because, as of now, there's no way I can scale past 25 images.

func hotButtonQuery() {
    if swipePosition == 0 {
        var query = PFQuery(className:"UserData")
        query.getObjectInBackgroundWithId("RlvK3GhfqE") {
            (userData: PFObject!, error: NSError!) -> Void in
            if error != nil {

                println(error)
            }

            else {
            userData.incrementKey("totalVotes", byAmount: 1)
            userData.incrementKey("hot", byAmount: 1)

                var updateTotalVotesUILabel = userData.objectForKey("totalVotes") as NSInteger

                var updateHotsUILabel = userData.objectForKey("hot") as NSInteger

                userData.saveInBackground()

                println("parse was updated!")

                self.totalVotesLabel.text = String(updateTotalVotesUILabel)
                self.totalHotsLabel.text = String(updateHotsUILabel)
            }
        }
    } else if swipePosition == 1 {
            var query = PFQuery(className:"UserData")
            query.getObjectInBackgroundWithId("30WlVtgurP") {
                (userData: PFObject!, error: NSError!) -> Void in
                if error != nil {

                    println(error)
                }

                else {
                    userData.incrementKey("totalVotes", byAmount: 1)
                    userData.incrementKey("hot", byAmount: 1)


                    var updateTotalVotesUILabel = userData.objectForKey("totalVotes") as NSInteger

                    var updateHotsUILabel = userData.objectForKey("hot") as NSInteger

                    //println(userData.objectForKey("totalVotes"))
                    //println("total HOTs:")
                    //println(userData.objectForKey("hot"))

                    userData.saveInBackground()

                    println("parse was updated!")


                    self.totalVotesLabel.text = String(updateTotalVotesUILabel)
                    self.totalHotsLabel.text = String(updateHotsUILabel)


                }
            }
    } else if swipePosition == 3 {
        var query = PFQuery(className:"UserData")
        query.getObjectInBackgroundWithId("5D6ARjk3xS") {
            (userData: PFObject!, error: NSError!) -> Void in
            if error != nil {

                println(error)
            }

            else {
                userData.incrementKey("totalVotes", byAmount: 1)
                userData.incrementKey("hot", byAmount: 1)


                var updateTotalVotesUILabel = userData.objectForKey("totalVotes") as NSInteger

                var updateHotsUILabel = userData.objectForKey("hot") as NSInteger

                //println(userData.objectForKey("totalVotes"))
                //println("total HOTs:")
                //println(userData.objectForKey("hot"))

                userData.saveInBackground()

                println("parse was updated!")


                self.totalVotesLabel.text = String(updateTotalVotesUILabel)
                self.totalHotsLabel.text = String(updateHotsUILabel)


            }
        }
    }

推荐答案

只需使用

query.whereKey("key", doesNotMatchKey: "matchcheck", inQuery: innerQuery)

这篇关于如何进行“不在"解析查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆