I have a doubt about classes that designate a delegate.
Sometimes the delegate object needs to implement a protocol, sometimes not. For example, if you want to display an UIAlertView
, you create it specifying a delegate
like self. Then, the class that is calling the UIAlertView
must implement the UIAlertViewDelegate
protocol.
If you create other classes like NSUrlConnection
with the connectionWithRequest:delegate:
message, you designate a delegate, which will receive the delegate messages sent from NSUrlConnection
as the connection progresses, but the object designated as a delegate do not have to implement a protocol.
Am I missing something? How do I understand when I should implement a protocol? Is it always clear from the API reference as it is for UIAlertViewDelegate
?
I've noticed that UIAlertView
reference only presents instance methods and tells you that you have to implement the UIAlertViewDelegate
protocol, while NSUrlConnection
does not talk about protocols to implement, but it has a delegate methods section.
Could NSUrlConnection
have been defined like the UIAlertView
class, without delegate methods but with a NSUrlConnectionDelegate
protocol.
Or am I missing the point? It seems to me two different ways for similar purposes, but maybe I am wrong. I hope I've been quite clear, I just want to fully understand the rationale behind this stuff.