1

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

user2924482
  • 8,380
  • 23
  • 89
  • 173
  • 1
    Don't do it between the &interface of `MyProtoco`. Do it above, also `@interface` needs a `@end` and `@protocol` too. – Larme Dec 07 '20 at 19:26

1 Answers1

4

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".

Larme
  • 24,190
  • 6
  • 51
  • 81