Reputation: 1951
I am trying to implement a protocol in Objective C.
@implementation UsingViewsViewController : UIViewController<UIAlertViewDelegate>
- (void)viewDidLoad
...
However, XCode issues an error: "Unexpected identifier or '('".
The code compiles, however, if I take out <UIAlertViewDelegate>
.
Why is it erring with the protocol notice?
Upvotes: 1
Views: 58
Reputation: 119144
You have your @interface and @implementation mixed up. Try:
@interface MyClass : UIViewController <UIViewAlertDelegate>
...
@end
@implementation MyClass
...
@end
Note that the @interface belongs in the header file, and the @implementation belongs in the .m file.
Upvotes: 2
Reputation: 6479
Put <UIAlertViewDelegate>
in your header (.h file)
@interface UsingViewsViewController : UIViewController<UIAlertViewDelegate> {
Your implementation (.m) should start that way:
@implementation UsingViewsViewController
Upvotes: 1