【问题标题】:load data using parse server in one array在一个数组中使用解析服务器加载数据
【发布时间】:2018-06-22 02:05:19
【问题描述】:

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

【问题讨论】:

  • Items 集合最好与User 集合分开

标签: arrays swift parse-platform


【解决方案1】:

您好,第一步是获取好友列表,然后是所有好友的帖子。

您必须通过使用 PFQuery 对象和方法 findObjectsInBackground 来请求当前用户的好友列表。在答案块中,您将收到一个 PFUser 数组。只需运行一个 for 循环并获取所有朋友的帖子。就是这样。

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)
        }
    }
}

【讨论】:

    猜你喜欢
    • 2019-04-08
    • 2019-01-21
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 2018-09-07
    • 2017-04-28
    • 1970-01-01
    • 2017-07-25
    相关资源
    最近更新 更多