DispatchQueue.global(qos: .background).async {
RccContactController.shared.updateDbForAppUsers(contactModels: contacts)
}
DispatchQueue.global(qos: .background).async {
RccContactController.shared.updateSyncStatus(lastCount : lastIndex)
DispatchQueue.main.async {
ContactDataStore.shared.updateContacts(withAppUsers: contacts)
if let safeDelegate = RccContactController.shared.delegate {
safeDelegate.syncedPhonebookContact(contacts: restContacts, appUsers: cont)
}
}
}
What's happening above:
- retrieving the synced contacts data from the server via Socket
- Update App users in DB in a background thread
- Update sync status in DB in a background thread and after the process notifies my controller through a delegate.
Sometimes I'm getting a crash in the second thread.
enqueued from com.apple.main-thread (thread 1)
What's wrong am I doing here?
Do like this:
General Example:
Perform only UI Operation in
DispatchQueue.main.async
rest of keep in a background thread.