ios - 解析 - 在特定行之后查询

标签 ios swift parse-platform pfquery

如何查询 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)
            }
        }
    }

这是我的解析数据库类: enter image description here

我想要的是仅查询在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)
        }
    }

您会注意到我使用以下方式比较了日期:NSDate Comparison using Swift

关于ios - 解析 - 在特定行之后查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37505153/

相关文章:

ios - UIView圆形 mask 动画

iOS 如何在不子类化所有内容的情况下为类引入具有 UDID 的能力?

iphone - 如果我弱链接应用程序中的所有框架会怎样?

java - Parse.com 安卓 : Number of ParseObjects I can pin to the Local Datastore?

cocoa - 将 iOS 移植到 Mac,创建 GUI、HOMEKIT 还是 Chameleon?

swift - 我有两个按钮,如果点击另一个按钮,如何更改其中一个按钮的图像? - swift

Swift objc_getAssociatedObject 始终为零

multithreading - 如何在执行后台任务时呈现 View Controller ?

swift - 访问 PFObject nsmutablearray 时 EXC__BAD_ACCESS 的 Xcode 6 beta 4 错误

swift - 如何显示用户在提要上发布消息的时间?