Tutorial :Do I need a protocol for notification?


I have classDownload that uses NSURLConnection. I'd like to keep all of the NSURLConnection events in classDownload. ClassA wants to use classDownload but also receive notifications such as connectionDidFinishLoading, which is called Finish in classDownload. How do I get the notifications from classDownload over to ClassA?


Assuming classDownload is the delegate of the NSURLConnection, you could just use NSNotificationCenter to broadcast events when the delegate methods are called. Then, in classA, subscribe to the events in classDownload using addObserver:. Let me know if you need any clarification or code snippets.


To directly answer the question in your title, no, you do not need a protocol to subscribe to events published by an object using NSNotificationCenter.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »