分析查询.whereKey
问题描述:
这是我的代码:分析查询.whereKey
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!)
你的第二个参数是一个布尔条件,和你想比较,为的字符串。创建一个“followedUser”和“PFUser.currentUser()!. objectId!”的字符串数组并使用 “whereKey:使用了:” 功能,而不是 “whereKey:equalTo”?”
你能告诉我的代码,我尝试这样做: 'VAR followedUser = [对象 “用户” 作为字符串 VAR currentUser! = PFUser.currentUser()?OBJECTID self.postedByUsers.append(followedUser) self.postedByUsers.append(currentUser!) 的println(self.postedByUsers) VAR postQuery:PFQuery = PFQuery(类名: “文章” ) postQuery.whereKey(“postedBy”,containedIn:self.postedByUsers) 'it dint work。 –
If by not not work y你的意思是它没有返回任何结果,那么我不确定你要求我做什么。如果它不能编译,那么这是一个单独的问题。它看起来像你记录你创建的数组。转到parse.com,转到您的Posts表格,查看postingBy列,看看是否有任何帖子符合您刚创建的条件,即“找到我的帖子,其中的帖子字符串等于这个或这个” –
我使用println后添加它给出这个阵列:[P2XutaEa6f,SiA72FwNi2] [P2XutaEa6f,SiA72FwNi2,xpkeERfmbz,SiA72FwNi2],实际上这是因为我追加它在for循环我猜。所以它追加第一个用户跟随当前用户和currentUserId,然后在第二个循环中的其他用户和当前userId ..我该如何解决这个问题? –