1

I am trying to load data using parse server but I do not know what kind of array I use. I want build app like snapchat - all post that user have should be in one array. I hope you understand what I'm saying.

This is the example :

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"]]],
    ]
}
1
  • The Items collection should ideally be separate from the User collection Commented Jan 12, 2018 at 15:58

1 Answer 1

2

Hi the first Step will be to get the friend list then the post of all the friends.

you have to request the Friend list of the current user by using a PFQuery Object and the method findObjectsInBackground. In the answer block you will receive an Array of PFUsers. Just run a for loop and fetch the Post of all friends. That is it.

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)
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.