I am fetching data from server in a method for eg - fetchData()
.
I want to write logic in such a way that if fetchData()
called twice(one after another) from different classes, both classes should be notified once network call is completed.
My fetchData() method is block based.
Basically, I want to achieve following- If n/w call is in progress, then another call to fetchDAta() should not initiate n/w call to get same data.
For Example
fetchData()
method is used to display data on two view controller Eg A and B.
If user is on controller A, then **fetchData()**
call will be initiated and if before its completion user moved to controller B which also calls fetchData() to show data. Then again network call or other operation will happen.
If we know that data is same, is there any way we can pass same data to controller B once first call to that method finishes without initiating the n/w call again?
how to call completion handler for both controllers A and B?