Skip to content

Instantly share code, notes, and snippets.

@theevo
Created May 11, 2020 01:51
Show Gist options
  • Select an option

  • Save theevo/6557cb3fdcb29df9201cc422f4415325 to your computer and use it in GitHub Desktop.

Select an option

Save theevo/6557cb3fdcb29df9201cc422f4415325 to your computer and use it in GitHub Desktop.
my first and successful implementation of DispatchGroup in Swift. I'm still shaky on why it works, but it does. 🤷
func constructUsers() {
print("#ChatListTVC Starting constructUsers()")
let group = DispatchGroup()
for otherUserUid in userUids {
group.enter() // entering the closure
User.getBy(uid: otherUserUid, completion: { (user) in
self.users.append(user)
print("Chat List appended: \(user.firstName)")
group.leave() // thread should leave here to run group.notify
})
}
group.notify(queue: .main) {
print("~~Reloading Chat List tableview~~")
self.tableView.reloadData()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment