Cannot find protocol definition for XXX

I first announced the protocol, and then used it. But I get the warning "I can not find the protocol definition for LeveyPopListViewDelegate." Here is the code:

@protocol LeveyPopListViewDelegate; @interface LeveyPopListView : UIView <LeveyPopListViewDelegate,UITableViewDataSource, UITableViewDelegate,UITextFieldDelegate> //the content of LeveyPopListView @end @protocol LeveyPopListViewDelegate <NSObject> //the definition for LeveyPopListViewDelegate @end 

if you first put the definition of LeveyPopListViewDelegate , I cannot use LeveyPopListView in the protocol.

+8
source share
7 answers

I always do this:

 @class LeveyPopListView; @protocol LeveyPopListViewDelegate <NSObject> //the definition for LeveyPopListViewDelegate @end @interface LeveyPopListView : UIView <LeveyPopListViewDelegate,UITableViewDataSource, UITableViewDelegate,UITextFieldDelegate> //the content of LeveyPopListView @end 
+1
source

I ended up suppressing all warnings for this particular line, which is not perfect, but works well.

 // Forward-declare protocols (to avoid circular inclusion) @protocol YourProtocol; #pragma clang diagnostic push // To get rid of 'No protocol definition found' warnings which are not accurate #pragma clang diagnostic ignored "-Weverything" @interface YourClass: NSObject // <YourProtocol> #pragma clang diagnostic pop 

Make sure you click & pop, otherwise you will get all warnings ignored for this file!

+6
source

If you followed the good advice in this post and there is still a problem, try just making a clean one. I scratched it a bit and the clean problem was resolved.

+2
source

First you need to define a protocol. Try below

 @protocol LeveyPopListViewDelegate <NSObject> //the definition for LeveyPopListViewDelegate @end @interface LeveyPopListView : UIView <LeveyPopListViewDelegate,UITableViewDataSource, UITableViewDelegate,UITextFieldDelegate> //the content of LeveyPopListView @end 
0
source

It is unusual to use a specific class name in a protocol definition. What you should do (in most cases exceptions may apply ... although they smell bad) make your class compatible with the protocol and use this class in the definition of the delegate protocol.

Also a bad smell is that the class should be its own delegate. I would carefully review the design.

0
source

This happened to me when I imported the Swift protocol into the Objective C class. What helped me was to add the *-Swift.h file of the Objective C class file:

 #import "MyApp-Swift.h" 

and declare the protocol as @objc :

 @objc protocol VerificationGate 
0
source

In addition, if you declared and defined the protocol in another file, you must #import this file, a preliminary declaration will not help in this situation.

BTW. Never suppress warnings, as some answers suggest.

0
source

All Articles