我正在尝试使用解析服务器加载数据,但我不知道我使用的是哪种数组。我想要构建像 snapchat 这样的应用程序——用户拥有的所有帖子都应该在一个数组中。我希望你明白我在说什么。
这是例子:
userArr = [
["name" : "Keila Maney", "pro-image" : "pro-img-3",
"items": [["content" : "image", "item" : "img-3"], ["content" : "video", "item" : "output"], ["content" : "video", "item" : "output2"]]],
["name" : "Gilberto", "pro-image" : "pro-img-1",
"items": [["content" : "video", "item" : "output3"], ["content" : "image", "item" : "img-4"], ["content" : "image", "item" : "img-5"], ["content" : "video", "item" : "output"]]],
["name" : "Jonathan", "pro-image" : "pro-img-2",
"items": [["content" : "image", "item" : "img-1"], ["content" : "video", "item" : "output2"]]],
["name" : "Delmer", "pro-image" : "pro-img-4",
"items": [["content" : "image", "item" : "img-2"], ["content" : "video", "item" : "output"], ["content" : "image", "item" : "img-3"]]],
["name" : "Carolyne", "pro-image" : "pro-img-3",
"items": [["content" : "video", "item" : "output"], ["content" : "image", "item" : "img-4"], ["content" : "video", "item" : "output3"], ["content" : "image", "item" : "img-3"]]],
["name" : "Sabine", "pro-image" : "pro-img-5",
"items": [["content" : "video", "item" : "output2"], ["content" : "image", "item" : "img-5"], ["content" : "video", "item" : "output3"]]],
]
}
最佳答案
您好,第一步是获取好友列表,然后获取所有好友的帖子。
您必须使用 PFQuery 对象和 findObjectsInBackground 方法来请求当前用户的好友列表。在答案 block 中,您将收到一个 PFUser 数组。只需运行一个 for 循环并获取所有 friend 的帖子。就是这样。
func getProfileTimeLine(completion:@escaping(_ posts: [Post]?, _ error:Error?)->Void){
let query = PFQuery(className: Post.className)
query.order(byDescending:"updatedAt")
query.whereKey("author", equalTo: Friend)
query.includeKey("author")
query.limit = 20
// fetch data asynchronously
query.findObjectsInBackground { (friendPosts, error) in
if error == nil{
if let postsObjects = friendPosts{
completion(postsObjects, error)
}
}else{
completion(nil, error)
}
}
}
关于arrays - 在一个数组中使用解析服务器加载数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48229159/