简体   繁体   English

导入协议时没有类型或协议错误

[英]No type or protocol error while protocol is imported

At first, in LoadingVC.h I declare a protocol: 首先,在LoadingVC.h中,我声明了一个协议:

@protocol VideoWorker <NSObject>

@required

@property (nonatomic) float progress;
@property (nonatomic) BOOL done;

-(void)beginWorking;

@end

@interface LoadingVC : UIViewController <UIAlertViewDelegate>
...
@end

then in BlurWorkerGPU.h 然后在BlurWorkerGPU.h中

...
#import "LoadingVC.h"

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

However, llvm says that 然而,llvm说

"No type or protocol named 'VideoWorker'" “没有名为'VideoWorker'的类型或协议”

which is strange since I am importing the header where the protocol is defined. 这很奇怪,因为我正在导入定义协议的标头。 Any clues? 有线索吗?

You should forward declare protocol in .h files before you use it. 在使用之前,您应该在.h文件中转发声明协议。 Put this in the top of BlurWorkerGPU.h 把它放在BlurWorkerGPU.h的顶部

@protocol VideoWorker;

检查是否在“LoadingVC.h”中导入“BlurWorkerGPU.h”

Possible solutions are 可能的解决方案

  • import protocol 导入协议

@import YOURPROTOCOLNAME @import YOURPROTOCOLNAME

  • import Class in which protocol is declared import声明协议的类

#import "YOURCLASSWHICHDECLAREDPROTOCOL.h"

  • Use @Class to import the class 使用@Class导入类

@class YOURCLASSWHICHDECLAREDPROTOCOL; @class YOURCLASSWHICHDECLAREDPROTOCOL;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM