views:

81

answers:

1

I have a class which routing many messages into inner component instance. So the class have only method definition, but no implementation. How can I suppress these warnings for those dynamic methods?

-- edited --

My code sample:

@interface SomeClass : NSObject
{
}
- (void)mssageA:(id)value1 additionalOption:(id)value2;
- (void)mssageB:(id)value1 additionalOption:(id)value2;
- (void)mssageC:(id)value1 additionalOption:(id)value2;
@end
@implementation SomeClass
- (id)forwardingTargetForSelector:(SEL)aSelector
{
    if(aSelector==@selector(mssageA:additionalOption:))     return  innerComponentInstance;
    if(aSelector==@selector(mssageB:additionalOption:))     return  innerComponentInstance;
    if(aSelector==@selector(mssageC:additionalOption:))     return  innerComponentInstance;

    return  [super forwardingTargetForSelector:aSelector];
}
@end
+1  A: 

I think a protocol implementation could look like this

@protocol SomeProtocol 

@optional
- (void)mssageA:(id)value1 additionalOption:(id)value2;
- (void)mssageB:(id)value1 additionalOption:(id)value2;
- (void)mssageC:(id)value1 additionalOption:(id)value2;

@interface SomeClass : NSObject <SomeProtocol>
{
}

@implementation SomeClass
- (id)forwardingTargetForSelector:(SEL)aSelector
{
    if(aSelector==@selector(mssageA:additionalOption:))     return  innerComponentInstance;
    if(aSelector==@selector(mssageB:additionalOption:))     return  innerComponentInstance;
    if(aSelector==@selector(mssageC:additionalOption:))     return  innerComponentInstance;

    return  [super forwardingTargetForSelector:aSelector];
}
@end
Erle
You need an @end at the end of the protocol, I think, but otherwise looks good.
Seamus Campbell
@optional looks contain a meaning of the implementations should be checked before using it with `respondsToSelector:`. Do I have wrong understanding about @optional keyword?
Eonil
oh of course i just forgot the @end, lazy me. It'll be better to check respondsToSelector. You can do it - so i think - without but risk a crash
Erle

related questions