FindObjectInBackgroundithBlock嵌套ios

FindObjectInBackgroundithBlock嵌套ios,ios,parse-platform,Ios,Parse Platform,我正在使用ios、swift和parse.com作为后端开发应用程序。 我的问题是,我需要在第二个查询对象中生成一个查询对象结果,如下面的代码所示。但当我使用下面的代码时,GUI会因为findObjects()方法而在一段时间内失去响应。我改用了FindObjectsInBackgroundithBlock(),但tableview self.posts在tableview中只显示一条记录。我在post表中有10条记录。 你们能告诉我如何解决下面的问题吗?实际上我不想使用findObjects(

我正在使用ios、swift和parse.com作为后端开发应用程序。 我的问题是,我需要在第二个查询对象中生成一个查询对象结果,如下面的代码所示。但当我使用下面的代码时,GUI会因为findObjects()方法而在一段时间内失去响应。我改用了FindObjectsInBackgroundithBlock(),但tableview self.posts在tableview中只显示一条记录。我在post表中有10条记录。 你们能告诉我如何解决下面的问题吗?实际上我不想使用findObjects()方法


一种选择是在类帖子中使“posturerName”成为指向Friends类的指针列,然后您只需要一个类似以下内容的查询:

var query = PFQuery(className:"Post")
query.includeKey("postusername") //this would include the object that it points to i.e. the Friends object you saved there
。。。然后在
for
循环中

for object in objects! {
    let friend = object["postusername"] // now friend is the Friends object
    let friendName:String = friend["friendname"] as? String
    friendArray.append(friendName)
}
注意:这要求您将“posturerName”保存为类朋友的PFObject。解析iOS文档可以很好地解释这一点


我已经通过使用关系查询解决了这个问题

var query = PFQuery(classWithName: "Post")
var fQuery = PFQuery(className:"Friends")
fQuery.whereKey("friendname", equalTo: cuser["fullname"])
query.whereKey("postusername", matchesKey:"whosefriend", inQuery:fQuery)

你已经试图解决这个问题了吗?如果你不想使用findObjects(),那为什么呢?你肯定不想使用findObjects,因为这是同步的,会阻塞主线程。感谢回复,我尝试使用FindObjectsInBackgroundithBlock而不是findObjects,但问题是它是异步函数,所以数据无法正确获取,所以我使用了findObjects,所以我获取数据并进行处理。您也可以为我的上述问题提供其他解决方案,我希望仅当登录用户是“已发布用户”的朋友时才在页面上显示帖子。您好,谢谢回复。当我添加新的post对象[“positionername”]=PFObject时,我在下面添加了一行(不带datawithclassname:“Friends”,objectId:PFUser.currentUser().objectId)但是当我在for循环中使用您的代码时,我得到了friend对象,但friendName得到了nil。嘿@abcdgef-在解析控制台中-您必须将postureName列更改为指向Friends类的指针列。这还要求您在posturerName列中保存一个Friends类的对象,即不仅仅是一个字符串。为此签出解析ios文档。另外,你想用
let post=post(….)self.posts.append(post)
Hi,我创建了这样的指针列,object[“postsername”]=PFObject(withoutDataWithClassName:“Friends”,objectId:PFUser.currentUser().objectId),可以吗?若使用您的代码,我不会得到friendname,实际上当任何朋友接受邀请时,记录已保存在Friends表中,而post表是用于用户向表中添加post时的
var query = PFQuery(classWithName: "Post")
var fQuery = PFQuery(className:"Friends")
fQuery.whereKey("friendname", equalTo: cuser["fullname"])
query.whereKey("postusername", matchesKey:"whosefriend", inQuery:fQuery)