Skip navigation.
 
mlRe: Category or Protocol? (objc newbie)
FROM : Nathan Day
DATE : Tue Apr 19 06:31:47 2005

You need to read up on formal versus informal protocols, a catagory interface without an implementation is called an informal protocol and it simply lets you attempt to send a message to an object without getting a compiler warning, it also servers a documentation of what methods the delegate can choose to implement.

The way you use it is something like this

if( [theDelegate respondsToSelector:@selector(delegateMethod)] )
    [theDelegate delegateMethod];

with out the catagory, the compile might complain that it doesn't know about the method if the user doesn't implement it. If you used a formal protocol instead then the person who write the delegate would have to implement the method 'delegateMethod', even if it doesn't do anything.

On Tuesday, April 19, 2005, at 02:13PM, Rick Kitts <<email_removed>> wrote:

>Hello. I'm working on a class that uses a delegate. I was looking at
>how Apple does this sort of thing and ran into NSXMLParser. It takes a
>delegate, of course, and the delegate interface is declared as follows:
>
>// The parser's delegate is informed of events through the methods in
>the NSXMLParserDelegateEventAdditions category.
>@interface NSObject (NSXMLParserDelegateEventAdditions)
>
>To be honest, I'm not sure that this means. Does
>NSXMLParserDelegateEventAdditions
>define a type that I can subclass?
>
>Coming from Java world my inclination is to use a Protocol and do:
>
>-(void)setDelegate:(id<MyProtocol>)delegate;
>
>This never seems to be done in any of the Apple stuff so I'm guessing
>my inclination is at least idiomatically wrong but, again, I'm not sure
>why.
>
>So, I guess what I'm asking is can anyone either a) explain what this
>stuff is trying to do or b) point me to some docs or a book that can
>help me understand this sort of thing? I have read the objc manual
>(PDF) from Apples site and I didn't see this sort of thing covered.
>
>Many thanks in advance for any assistance,
>---Rick
>
> _______________________________________________
>Do not post admin requests to the list. They will be ignored.
>Cocoa-dev mailing list      (<email_removed>)
>Help/Unsubscribe/Update your Subscription:
>http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>
>This email sent to <email_removed>
>
>



Nathan Day
<email_removed>
http://homepage.mac.com/nathan_day/

Related mailsAuthorDate
mlCategory or Protocol? (objc newbie) Rick Kitts Apr 19, 04:36
mlRe: Category or Protocol? (objc newbie) Andrew White Apr 19, 06:28
mlRe: Category or Protocol? (objc newbie) Nathan Day Apr 19, 06:31
mlRe: Category or Protocol? (objc newbie) Rick Kitts Apr 19, 17:33
mlRe: Category or Protocol? (objc newbie) Ondra Cada Apr 19, 18:52
mlRe: Category or Protocol? (objc newbie) Rick Kitts Apr 19, 21:40
mlRe: Category or Protocol? (objc newbie) Ondra Cada Apr 19, 21:56
mlRe: Category or Protocol? (objc newbie) Charilaos Skiadas Apr 19, 22:04
mlRe: Category or Protocol? (objc newbie) John Brownlow Apr 19, 22:11
mlEffective Cocoa (was Category or Protocol? (objc newbie)) Keith Alperin Apr 19, 22:13
mlRe: Effective Cocoa (was Category or Protocol? (objc newbie)) Rick Kitts Apr 19, 22:21
mlRe: Effective Cocoa (was Category or Protocol? (objc newbie)) Shawn Erickson Apr 19, 22:21
mlRe: Effective Cocoa (was Category or Protocol? (objc newbie)) Finlay Dobbie Apr 19, 22:54
mlRe: Effective Cocoa (was Category or Protocol? (objc newbie)) Ondra Cada Apr 19, 23:44
mlRe: Category or Protocol? (objc newbie) Ondra Cada Apr 19, 23:47