开发者

MulticastDelegate in ObjectiveC

I'm using MulticastDelegate class which is part of xmpp framework and taken here It works perfect for me! However I got warning:

'MulticastDelegate' may not respond to 'someMethod'

Is there a开发者_开发百科ny way to avoid the warning for this class? Thanks in advance.


What kind of someMethod is that? Did you include the MulticastDelegate.h header?


Update: Aha, in that case you need to tell the compiler that the delegate implements the Notifier interface:

#import "MulticastDelegate.h"

@protocol Notifier
- (void) someMethod; 
@end

@interface Manager
{
   MulticastDelegate <Notifier> delegate;
}
@end

This should do. But isn’t the code a bit fishy? How do you know that the delegate implements someMethod when delegate is a plain MulticastDelegate? Are you omitting something in the example?


As long as you have imported "MulticastDelegate.h" and someMethode is part of the public interface of the class as declared in "MulticastDelegate.h", you shouldn't get this warning.

GCC issues this warning only on the ocassion you send a message to an object which does not publicly declare to respond to that message.


I have a protocol

@protocol Notifier
 -(void) someMethod; 
@end

and class

#import "MulticastDelegate.h"

@interface Manager
{
       MulticastDelegate delegate; 
}
@end

somewhere in the implementation file

delegate= [[MulticastDelegate alloc] init];
.....
- (void)addDelegate:(id)_delegate
{
    [delegate addDelegate:_delegate];
}

and then

[delegate someMethod];

Line above causes the warning I mentioned in my question.

'MulticastDelegate' may not respond to 'someMethod'

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜