No type or protocol error when importing a protocol

First, in LoadingVC.h, I declare the protocol:

@protocol VideoWorker <NSObject> @required @property (nonatomic) float progress; @property (nonatomic) BOOL done; -(void)beginWorking; @end @interface LoadingVC : UIViewController <UIAlertViewDelegate> ... @end 

then at BlurWorkerGPU.h

 ... #import "LoadingVC.h" @interface BlurWorkerGPU : NSObject <VideoWorker> { ... } - (void)beginWorking; @property(nonatomic)float progress; @property(nonatomic)BOOL done; ... @end 

However, llvm says that

"No type or protocol named" VideoWorker "

which is strange as I import the header where the protocol is defined. Any clues?

+5
source share
3 answers

Before using it, you must forward the protocol of the protocol to .h files. Put it at the top of BlurWorkerGPU.h

 @protocol VideoWorker; 
+13
source

check if you are importing "BlurWorkerGPU.h" into "LoadingVC.h"

0
source

Possible solutions:

  • import protocol

@import YOURPROTOCOLNAME

  • import The class in which the protocol is declared

#import "YOURCLASSWHICHDECLAREDPROTOCOL.h"

  • Use @Class to import a class

@class YOURCLASSWHICHDECLAREDPROTOCOL;

0
source

Source: https://habr.com/ru/post/1243959/


All Articles