Ext.: Http://stackoverflow.com/questions/11382057/declaring-a-delegate-protocol
There definitely is subtle differences. If the protocol you is talking about isADelegateThat isUsed by one particularclass, forExample, Myspecialviewcontroller, and myspecialviewcontrollerdelegate, then you might very-like to keep the Declarati On both of thoseinchThe same header. If anotherclass isGoing to implement that protocol, forexample, it's probably going to depend logically on the Myspecialviewcontroller class. So, you're not introducing any additional dependencies. But, there's Another significant reason (at least) to use protocols. You might is trying to decouple a bidirectional dependency between. Of course, the compiler doesn'T let's headers#importone another. But, evenifYou move oneclass's #import to the. m file, it's often a sign of a poor design to has a classes each fully aware of one another's complete API.One-to- decouple ThisRelationship a little isTo make oneclassAware of the other is only through a protocol and the other implements. Perhaps Parent owns and creates the childclass, and thus must#import "Child.h". But the child also needs to the Foo:bar:method on the Parent. Could make a fooprotocol:@protocolFooprotocol- (void) Foo: (int) arg1 bar: (BOOL) arg2;@end and theninchParent.h:@interfaceParent:somebaseclass<fooprotocol>{}which allows child to Do This:@interfaceChild {} @property (assign)ID<FooProtocol>Foohandler;and use it[foohandler foo:1Bar:yes]; Which leaves the child with no direct dependency on the Parentclass(or Parent.h). But, Thisonly worksifYou keep the declaration of FooprotocolinchFooProtocol.h, notinchParent.h. Again,if ThisFooprotocol is only ever used by child and then it would make sense to keep itinchChild.h, but probably notif Thisprotocol was used by classes other than child.so, to summarize, keep your protocolsinchSeparate headersifYou want to preserve the maximum ability to separate interdependencies between your classes, or to encourage better Separa tioninchYour design.
# # Baidu Video iOS version delegate is written separately in an. h file.
Delegate integrated in the class, or is it written separately in the. h file?