Objective c 编译器警告和-(void)转发调用:(NSInvocation*)iInvocation

Objective c 编译器警告和-(void)转发调用:(NSInvocation*)iInvocation,objective-c,compiler-warnings,message-forwarding,Objective C,Compiler Warnings,Message Forwarding,我有一个类,它主要将其方法实现委托给一个成员变量 为了简化编写,我实现了 -(void)forwardInvocation:(NSInvocation *)iInvocation; 及 这使我的类能够在不使用大量样板代码的情况下实现一些协议 它工作得很好,只是编译器对我没有实现的所有方法都发出警告,这些方法实际上被转发到成员变量。 我有没有办法告诉系统这些方法实际上已经实现了,或者只是为了那个来源而关闭那些警告 编译器发出3种警告: 协议中的方法未实现 属性XXX需要方法XXX 待实施不完全

我有一个类,它主要将其方法实现委托给一个成员变量

为了简化编写,我实现了

-(void)forwardInvocation:(NSInvocation *)iInvocation; 

这使我的类能够在不使用大量样板代码的情况下实现一些协议

它工作得很好,只是编译器对我没有实现的所有方法都发出警告,这些方法实际上被转发到成员变量。 我有没有办法告诉系统这些方法实际上已经实现了,或者只是为了那个来源而关闭那些警告

编译器发出3种警告:

  • 协议中的方法未实现
  • 属性XXX需要方法XXX
  • 待实施不完全实施
  • 在下面的代码中,我委托给的对象的类是
    ShareUser
    ,实例是
    \u user

    -(void)forwardInvocation:(NSInvocation *)iInvocation
    {
        SEL aSelector = [iInvocation selector];
        if ([ShareUser instancesRespondToSelector:aSelector])
            [iInvocation invokeWithTarget:_user];
        else
            [self doesNotRecognizeSelector:aSelector];
    }
    -(NSMethodSignature*)methodSignatureForSelector:(SEL)aSelector
    {
        if ([ShareUser instancesRespondToSelector:aSelector])
            return [ShareUser instanceMethodSignatureForSelector:aSelector];
    
        return nil;
    }
    
    可能重复的问题虽然相关(我在以前的搜索中没有找到这个问题),但这不是同一个问题。在我的例子中,转发类实现了一个协议,所有调用都是对协议方法的,因此在调用该方法时没有警告。问题是当我的类被编译时,我有很多警告。我已经更新了原始帖子以显示警告
    -(void)forwardInvocation:(NSInvocation *)iInvocation
    {
        SEL aSelector = [iInvocation selector];
        if ([ShareUser instancesRespondToSelector:aSelector])
            [iInvocation invokeWithTarget:_user];
        else
            [self doesNotRecognizeSelector:aSelector];
    }
    -(NSMethodSignature*)methodSignatureForSelector:(SEL)aSelector
    {
        if ([ShareUser instancesRespondToSelector:aSelector])
            return [ShareUser instanceMethodSignatureForSelector:aSelector];
    
        return nil;
    }