Justin Copeland
Justin Copeland

Reputation: 1951

Why does implementing this protocol return an error?

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

Answers (2)

James Eichele
James Eichele

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

Andy Friese
Andy Friese

Reputation: 6479

Put <UIAlertViewDelegate> in your header (.h file)

@interface UsingViewsViewController : UIViewController<UIAlertViewDelegate> {

Your implementation (.m) should start that way:

@implementation UsingViewsViewController

Upvotes: 1

Related Questions