I've recently started to do some more complicated programming with network-related work on iOS with Swift. This introduced a lot of asynchronous code not only in networking but also some exchange of information between view controllers.
Anyway, my question is simple, and can be quite general. As far as I know, there are (at least) four ways to do callback, so is there a general rule as to which is better in each case?
- callback closure (function) as a function argument
- delegation with protocol
- notification (or observer)
- shared state object
Use cases in my application
- Network stuff, POST request or download file
- passing data one-way between view controllers on button tap
- passing data both-ways between view controllers (One view shows the selected option, another view gives the real options for user to select)