How to conform to a self-made protocol?

后端 未结 7 1774
忘了有多久
忘了有多久 2021-02-10 16:33

I have a class with an delegate property. Anyone who wants to be a delegate must conform to a protocol. I defined everything like this:

#import 

        
7条回答
  •  花落未央
    2021-02-10 17:31

    The compiler's warning is correct. OtherClass doesn't conform to the protocol because it doesn't declare the required fooBarWithFoo method that the protocol expects.

    Have you tried it this way?

    #import "MyClass.h"
    
    @interface OtherClass : NSObject  {
        // ivars
    }
    
    - (void)fooBarWithFoo:(CGFloat)foo; // <<< missing bit
    
    @end
    

提交回复
热议问题