Created
May 11, 2020 01:51
-
-
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. 🤷
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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