Swift 4.1. First create a concurrent Queue
private let concurrentPhotoQueue = DispatchQueue(label: "App_Name", attributes: .concurrent)
Now dispatch your work to Concurrent Queue
concurrentPhotoQueue.async(flags: .barrier) { [weak self] in
// 1
guard let weakSelf = self else {
return
}
// 2 Perform your task here
weakSelf.passingMsgIdsTofetchMsgss(messageIDs : msgIDBatches[0])
weakSelf.passingMsgIdsTofetchMsgss(messageIDs : msgIDBatches[1])
weakSelf.passingMsgIdsTofetchMsgss(messageIDs : msgIDBatches[2])
weakSelf.passingMsgIdsTofetchMsgss(messageIDs : msgIDBatches[3])
// 3
DispatchQueue.main.async { [weak self] in
// Update your UI here
}
}