Reputation: 9499
I am trying to define my protocol so that the class implementing it has to also be a UIViewController
.
So i typed the following code into a header file:
#import <UIKit/UIKit.h>
#import <UIKit/UIViewController.h>
#import <EventKit/EventKit.h>
#import <EventKitUI/EventKitUI.h>
@protocol MySuperProtocol<UIViewController> // <-- here
@property(nonatomic, weak, nullable) id<EKEventViewDelegate> delegate;
@end
I always get the error saying that:
Cannot find protocol declaration for 'UIViewController'
If i replace UIViewController
with NSObject
, code compiles. If i remove the <>
inheritance after the protocol, code compiles.
I tried all combinations of
#import <UIKit/UIKit.h>
#import <UIKit/UIViewController.h>
to no avail.
What am i doing wrong?
Upvotes: 0
Views: 467
Reputation: 114855
You are misunderstanding the syntax. @protocol MySuperProtocol<UIViewController>
doesn't establish a constraint that implementers of MySuperProtocol
must be UIViewController
s. It says that MySuperProtocol
conforms to UIViewController
However, unlike NSObject
, UIViewController
is not a protocol; it is a class. A protocol cannot conform to a class, only to another protocol.
You can refer to the documentation:
Protocols inherit from other protocols
In the same way that an Objective-C class can inherit from a superclass, you can also specify that one protocol conforms to another.
There is no way to constrain protocol adoption in Objective C.
Upvotes: 1