Skip to content

Instantly share code, notes, and snippets.

@scottdelly
Created January 26, 2016 06:58
Show Gist options
  • Save scottdelly/ba739014d0052dfb0300 to your computer and use it in GitHub Desktop.
Save scottdelly/ba739014d0052dfb0300 to your computer and use it in GitHub Desktop.
let contactsGroup = dispatch_group_create()
dispatch_group_enter(contactsGroup) //Enter group for the first time
loadContactsFromServerAPIWithCompletion({ (contacts:[User]) -> () in
doStuffWithContacts(contacts)
dispatch_group_leave(contactsGroup) //Leave group
})
dispatch_group_enter(contactsGroup) //Enter group again
loadContactsAddressBookWithCompletion({ (contacts:[User]) -> () in
doStuffWithContacts(contacts)
dispatch_group_leave(contactsGroup) //Leave group
})
//GCD stores this block to be called once the group "contactsGroup" has no more entrants
dispatch_group_notify(contactsGroup, dispatch_get_main_queue(), { [weak self] () -> Void in
sortContacts()
tableView.reloadData()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment