Reputation: 1236
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"]]],
]
}
Upvotes: 1
Views: 39
Reputation: 56
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)
}
}
}
Upvotes: 2