I have custom UIView class GestureView. I have a forward declaration for this class and it’s delegate below. I have imported GestureView.h in .m file. This works fine but iOS gives warning message saying “Cannot find protocol definition for GestureViewDelegate”. If I remove forward declaration it gives same warning message as error. I don’t want to import GestureView.h from ContainerViewController.h as I usually imports stuffs in .m file. Could someone please explain what’s wrong in following class structure?
ContainerViewController.h
#import <UIKit/UIKit.h>
@class DividerView;
@class GestureView;
@protocol GestureViewDelegate;
@interface ContainerViewController : UIViewController<GestureViewDelegate>
@property (strong, nonatomic) IBOutlet GestureView *topContentView;
@end
GestureView.h
#import <UIKit/UIKit.h>
@protocol GestureViewDelegate;
@interface GestureView : UIView
- (void)initialiseGestures:(id)delegate;
@end
@protocol GestureViewDelegate <NSObject>
@required
- (void)GestureView:(GestureView*)view handleSignleTap:(UITapGestureRecognizer*)recognizer;
@end
I like that you’re trying to avoid imports in header files: very good practice. However, to fix your bug you can just make your code even better! In my opinion it’s not really necessary that your
ContainerViewControllerclass outwardly declares that it supportsGestureViewDelegateprotocol, so you should move this into your implementation file. Like so:GestureView.h
ContainerViewController.h
ContainerViewController.m