ios - 解析查询 .whereKey

标签 ios swift parse-platform pfquery

这是我的代码:

 func loadData() {

    data.removeAllObjects()
    isLiking.removeAll(keepCapacity: true)
    likes.removeAll(keepCapacity: true)

    var followedUserQuery:PFQuery = PFQuery(className: "Followers")
        followedUserQuery.whereKey("follower", equalTo: PFUser.currentUser()!.objectId!)

        followedUserQuery.findObjectsInBackgroundWithBlock { (objects, error) -> Void in

            if let objects = objects {

                for object in objects {

                    var followedUser = object["user"] as! String


                    println(followedUser)

                    var postQuery:PFQuery = PFQuery(className: "Posts")
                          var postQuery:PFQuery = PFQuery(className: "Posts")
     postQuery.whereKey("postedBy", equalTo: followedUser || PFUser.currentUser()!.objectId!) // cannot invoke 'whereKey' with an argument list of type '(String, equalTo: Bool)'

                          postQuery.orderByDescending("createdAt")
                          postQuery.findObjectsInBackgroundWithBlock ({ (objects, error) -> Void in

                        if let objects = objects {

                            for object in objects {

                                if let post = object as? PFObject {

                                    self.data.addObject(object)

我在代码中收到上面注释的错误。我想从 Posts 类中检索 posts ,该类将由关注的用户发布并由当前用户发布。我怎样才能做到这一点?我也尝试过这个:

  var postQuery:PFQuery = PFQuery(className: "Posts")
      postQuery.whereKey("postedBy", equalTo: followedUser)
      postQuery.whereKey("postedBy", equalTo:   PFUser.currentUser()!.objectId!) 

通过使用这个我只获取当前用户的帖子。

但这确实有效。 有没有其他方法可以获取关注用户和当前用户发布的帖子?我愿意接受任何类型的建议。

最佳答案

这行代码的语法错误:

postQuery.whereKey("postedBy", equalTo: followedUser || PFUser.currentUser()!.objectId!)

您的第二个参数是一个 bool 条件,您正在尝试将其与字符串进行比较。创建“followedUser”和“PFUser.currentUser()!.objectId!”的字符串数组并使用“whereKey:containedIn:”函数,而不是“whereKey:equalTo””

关于ios - 解析查询 .whereKey,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32023763/

相关文章:

ios - 通过 Segues 持久化

ios - 在哪里可以存储我的 IOS 证书文件 (.p12)?

ios - 约束并没有扩大我对方向变化的看法

ios - 在 TableView 选项中获取行 ID

ios - 为什么 RxSwift 与多个可观察量连接似乎不起作用?

android - 无法在 Trigger.io Android 应用程序上启动接收器 com.parse.ParseBroadcastReceiver

xcode - 解析和 Swift Xcode 6.3 问题

ios - 未从 Collection View 调用 prepareForSegue

ios - 尝试使用 Parse 显示查询的用户信息

javascript - 在 javascript 中查询解析