قالب وردپرس درنا توس
Home / IOS Development / How do I make calls back to each other in Swift? : iOSProgramming

How do I make calls back to each other in Swift? : iOSProgramming



I have a method that sorts items that come from two different sources and adds them to tableView, both sources are named simultaneously, and can return results independently. How do I make sure that if a new call comes, is it going to wait for the last one in the end? I don't think it's a good idea to allow two or more simultaneous changes to the data source

What I mean:

      func fetchPlaylists () {
self.repo.getAllPlaylists (from: [.source1, .source2]) {[weak self] result in
change result {
case .success (leave playlists):
// Wait for the previous callback to complete the sortIncoming method
self? .sortIncoming (playlists: playlists)
case. errors (leave errors):
print (error.localizedDescription)
}
}
}

private func sortIncoming (playlists: [AWPlaylist]) {
...
insertToTableViewClosure? (sections, rows)
}

Source link