How can I differentiate the same method name of two protocols in a class implementation?

后端 未结 2 1342
栀梦
栀梦 2021-02-09 05:42

I have two protocols

@protocol P1

-(void) printP1;

-(void) printCommon;

@end


@protocol P2

-(void) printP2;

-(void) printCommon;
@end

Now

2条回答
  •  难免孤独
    2021-02-09 06:40

    for me the following code did worked:

    @protocol P1    
    
    - (void) method1;
    
    @end
    
    @protocol P2
    
    - (void) method1;
    - (void) method2;
    
    @end
    
    @interface C1 : NSObject
    
    @end
    
    @implementation C1
    
    - (void) method1
    {
        NSLog(@"method1");
    }
    
    - (void) method2
    {
        NSLog(@"method2");
    }
    
    @end
    

    Compiler user: Apple LLVM 3.0 But if you're designing a solution like this, try to avoid such situations.

提交回复
热议问题