So I'm trying to wrap my head around Objective-C interfaces, delegates and protocols. So I have a question:
Does a delegate have to be in a separate file or can it be methods defined in your class?
Is a protocol like a java interface? This is the way I understand it at the moment where it basically makes you implement methods if you use this protocol.
I'm still confused about interfaces. I'm pretty sure they have no resemblance to what an interface is in java. Maybe it's just a declaration of variables that will be implemented in the class.
A delegate protocol needs to be defined as such
@protocol
//methods
@end
it can be put in any .h class, you just need to import i t whenever you are going to use it.
A protocol is not like a java interface, a protocol is an adapter that allows two classes to works together. Basically it says, if you want class A to send you messages about its state and actions these are the methods it will call on its delegate that you must implement. Its not like an interface because an interface says if you want to subclass this class you must implement these methods, the protocol says if you want to interact with this class you must implement these methods, so its somewhat different.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With