arrays - 在一个数组中使用解析服务器加载数据

标签 arrays swift parse-platform

我正在尝试使用解析服务器加载数据,但我不知道我使用的是哪种数组。我想要构建像 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/

相关文章:

actionscript-3 - 快速确定数据在数组中的位置

swift - 用解析中的数据填充 TableView

ios - AnyObject 上的算术运算失败

javascript - 从数组中提取子数组的内存最安全方法

ios - swift 3 通过字典中键的字符串值过滤字典数组

ios - tableView heightForRowAtIndexPath 不工作

ios - 在键盘上打字时,点击按钮无法被识别

ios - 让多个 IF 语句子句协同工作

ios - 如何使用 parse.com 服务器 iOS 保存对象数组?

java - 如何解决这段代码中的 ArrayIndexOutOfBoundsException?