解析-在特定行后查询 [英] Parse - Query after a specific row

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

问题描述

如何查询objectId等于我存储的objectId的特定行之后?

这是我的查询代码:

func queryStory(){
        let query = PFQuery(className: "myClassStory")
        query.whereKey("isPending", equalTo: false)
        query.limit = 1000
        query.orderByDescending("createdAt")

        query.findObjectsInBackgroundWithBlock { (posts: [PFObject]?, error: NSError?) -> Void in
            if (error == nil){
                // Success fetching objects

                for post in posts! {

                    if let imagefile = post["userFile"] as? PFFile {
                        self.userFile.append(post["userFile"] as! PFFile)
                        self.objID.append(post.objectId!)
                        self.createdAt.append(post.createdAt!)
                    }
                }
                print("Done!")
            }
            else{
                print(error)
            }
        }
    }

这是我的Parse数据库类:

我想要的是仅查询objectId:woaVSFn89t之后创建的项目.我该怎么办?

解决方案

找到对象后尝试对其进行过滤:

query.findObjectsInBackgroundWithBlock { (posts: [PFObject]?, error: NSError?) -> Void in
        if (error == nil){
            // Success fetching objects

            var thePostTime = NSDate()

            for post in posts! {
                if post.objectId == "The Object Id You Were Trying To Find" {
                    thePostTime = post.createdAt!
                }
            }

            for post in posts! {

                if post.createdAt!.isGreaterThan(thePostTime) == true {
                    if let imagefile = post["userFile"] as? PFFile {
                        self.userFile.append(post["userFile"] as! PFFile)
                        self.objID.append(post.objectId!)
                        self.createdAt.append(post.createdAt!)
                    }
                }

            }

            print("Done!")
        }
        else{
            print(error)
        }
    }

您会注意到我使用以下方法比较了日期:使用Swift进行NSDate比较

How can I query after a specific row where the objectId is equal to a objectId I have stored?

This is my query code:

func queryStory(){
        let query = PFQuery(className: "myClassStory")
        query.whereKey("isPending", equalTo: false)
        query.limit = 1000
        query.orderByDescending("createdAt")

        query.findObjectsInBackgroundWithBlock { (posts: [PFObject]?, error: NSError?) -> Void in
            if (error == nil){
                // Success fetching objects

                for post in posts! {

                    if let imagefile = post["userFile"] as? PFFile {
                        self.userFile.append(post["userFile"] as! PFFile)
                        self.objID.append(post.objectId!)
                        self.createdAt.append(post.createdAt!)
                    }
                }
                print("Done!")
            }
            else{
                print(error)
            }
        }
    }

This is my Parse database class:

What I want, is to only query the items that was createdAt after the objectId: woaVSFn89t. How can I do this?

解决方案

Try filtering the objects once you have found them:

query.findObjectsInBackgroundWithBlock { (posts: [PFObject]?, error: NSError?) -> Void in
        if (error == nil){
            // Success fetching objects

            var thePostTime = NSDate()

            for post in posts! {
                if post.objectId == "The Object Id You Were Trying To Find" {
                    thePostTime = post.createdAt!
                }
            }

            for post in posts! {

                if post.createdAt!.isGreaterThan(thePostTime) == true {
                    if let imagefile = post["userFile"] as? PFFile {
                        self.userFile.append(post["userFile"] as! PFFile)
                        self.objID.append(post.objectId!)
                        self.createdAt.append(post.createdAt!)
                    }
                }

            }

            print("Done!")
        }
        else{
            print(error)
        }
    }

You will notice that I compared the dates using this: NSDate Comparison using Swift

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

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