Do I need a protocol for notification?

I have a Download class that uses NSURLConnection. I would like to store all NSURLConnection events in classDownload. ClassA wants to use classDownload, but also receive notifications like connectionDidFinishLoading called Finish in classDownload. How to get notifications from classDownload to ClassA?

0


a source to share


1 answer


Assuming it classDownload

is a delegate NSURLConnection

, you can simply use NSNotificationCenter

to broadcast events when calling the delegate's methods. Then in classA

subscribe to events in classDownload

using addObserver:

. Let me know if you need clarification or code snippets.

Edit



To directly answer the question in your title, no, you don't need a protocol to subscribe to events posted by an object using NSNotificationCenter

.

+2


a source







All Articles