user2924482
user2924482

Reputation: 9140

Objective-C: declaring @protocol generates error Illegal interface qualifier

I'm trying to implement a @protocol/delegate but I'm getting this error:

Illegal interface qualifier

Here is my code:

//
//  MyProtocol.m
//  Apple-ObjC
//
//

#import <Foundation/Foundation.h>

@interface MyProtoco : NSObject
@protocol SampleProtocolDelegate <NSObject>

@end

Any of you knows why I'm getting this error or how can I fix it?

I'll really appreciate your help.

enter image description here

Upvotes: 1

Views: 218

Answers (1)

Larme
Larme

Reputation: 26096

You need to see the architecture of the file. You can't put @protocol like that between @interface and @end. Also, @protocol needs @end and so do @interface.

@protocol SampleProtocolDelegate <NSObject>
// Related to SampleProtocolDelegate
@end
@interface MyProtoco : NSObject
// Related to MyProtoco
@end

You can have various protocols/interface, you just need to put them one after the other. They are the the same "level" of declaration:

@protocol SampleProtocolDelegate <NSObject>
// Related to SampleProtocolDelegate
@end
@interface MyProtoco : NSObject
// Related to MyProtoco
@end   
@protocol SampleProtocolDelegate2 <NSObject>
// Related to SampleProtocolDelegate2
@end
@interface MyProtoco2 : NSObject
// Related to MyProtoco2
@end
@interface MyProtoco3 : NSObject
// Related to MyProtoco3
@end
@protocol SampleProtocolDelegate4 <NSObject>
// Related to SampleProtocolDelegate4
@end
@protocol SampleProtocolDelegate5 <NSObject>
// Related to SampleProtocolDelegate5
@end

With 2 protocols consecutive and two interfaces too to illustrate the "level".

Upvotes: 4

Related Questions