Skip to content

Instantly share code, notes, and snippets.

@shakked
Created October 9, 2015 14:38
Show Gist options
  • Save shakked/9d108a000f8692c74794 to your computer and use it in GitHub Desktop.
Save shakked/9d108a000f8692c74794 to your computer and use it in GitHub Desktop.
let group = dispatch_group_create()
dispatch_group_enter(group)
self.analyticCrawler.fetchLikes { (succeeded, likes) -> (Void) in
if succeeded {
self.likes = likes
} else {
self.likes = []
}
dispatch_group_leave(group)
}
dispatch_group_enter(group)
self.analyticCrawler.fetchComments { (succeeded, comments) -> (Void) in
if succeeded {
self.comments = comments
} else {
self.comments = []
}
dispatch_group_leave(group)
}
dispatch_group_notify(group, dispatch_get_main_queue()) {
var userInteractions : [String : UserInteraction] = Dictionary<String, UserInteraction>()
for like in self.likes! {
if let userInteraction = userInteractions[like.userSummary.username] {
userInteraction.addLike(like)
} else {
let userInteraction = UserInteraction(userSummary: like.userSummary)
userInteraction.addLike(like)
userInteractions[like.userSummary.username] = userInteraction
}
}
for comment in self.comments! {
if let from = comment.from {
if let userInteraction = userInteractions[from.username] {
userInteraction.addComment(comment)
} else {
let userInteraction = UserInteraction(userSummary: from)
userInteraction.addComment(comment)
userInteractions[from.username] = userInteraction
}
}
}
self.userInteractions = Array(userInteractions.values)
completion(true)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment