我在旧的iOS应用程序上运行ARC“重构”。

但是,我收到以下错误

Receiver type 'WarningCallback' for instance message is a forward declaration


WarningCallback.h

@class WarningCallback;

#import <UIKit/UIKit.h>
#import "WebViewController.h"
#import "Constants.h"

@protocol WarningCallback
-(void) warningDismissedAndNavigateToCall:(BOOL) navigateToCall;
@end

@interface WarningViewController : WebViewController {
}
@property (nonatomic,retain) WarningCallback* parentVC;

@end


WarningCallback.m

#import "WarningViewController.h"


@implementation WarningViewController

@synthesize parentVC;

...

-(IBAction) done:(id) sender {

[[self parentVC] warningDismissedAndNavigateToCall:NO];

}




@end


该错误发生在WarningCallback.m的以下行

   [[self parentVC] warningDismissedAndNavigateToCall:NO];

最佳答案

该错误是由于行@class WarningCallback;。该错误消息表示编译器找到了WarningCallback的前向声明,但找不到相应的实现。这是因为WarningCallback不是类,而是协议。

如果要转发声明协议,可以按照以下步骤进行:

@protocol WarningCallback;

@interface WarningViewController : WebViewController

@property (nonatomic, weak) id<WarningCallback> parentVC;

@end

@protocol WarningCallback

- (void)warningDismissedAndNavigateToCall:(BOOL) navigateToCall;

@end


请注意我如何声明parentVC

10-06 01:45