Notifications vs delegates

Hello, I am getting very confused about how to solve this issue: Suppose I send 3 network requests from my repository and i need to notify my viewcontroller after third request is successful and it receives json. After that I send third request again and waiting for new results… how can I notify my viewcontroller without starting request from viewontroller and sending closure back??? Notification center is bad the way I heard it… possible memory leaks… What about delegates or closures? Please provide best, most performant and adopted version… Also, I can’t use any third party.
So I will repeat once again: how can I notify particular viewController then results were received after starting request from different model? If someone uses notificationcenter please provide example with no memory leaks… I am tired of bad and incomplete examples.

I might switch to react native if no solutions found… this is really disappointing.

Hi Viktor,

You can achieve the same result with both, notifications and delegates, without any issues, the choice really depends on your architecture.

Do you have dedicated classes for making network requests and handling the model ?

PS : Switching to React Native doesn’t help if you don’t understand what you’re doing

Task continuation usually works, unless I misunderstand your question:
let session = URLSession.shared

session.dataTask(with: request1) { data, response, error in
// check for errors
// parse the response data

session.dataTask(with: request2) { data, response error in
// check for errors
// parse the response data

// if everything succeeded...
callbackQueue.async {
  completionHandler(result1, result2)


Hi @wellbranding,
From the description you have above, what you are after is a chained get, which relies on the results from the previous ones.

If you mentioned ReactNative, then you are used to a particular way of dealing with this, the closest that you can get is with using AlamoFire which would offer you a similar API.

If you do not want to use a 3rd party, then you can try chaining them or using a queue.



This topic was automatically closed after 166 days. New replies are no longer allowed.