live2dream95
live2dream95

Reputation: 6067

ObjectiveC Syntax for Specifying Protocol Name in Method Argument

What's the ObjectiveC syntax for specifying a protocol as an argument in a method?

Say I have 2 protocols, MyProtocol and MyProtocolCB:

@protocol MyProtocolCB <NSObject>
- (void) func;
@end

@protocol MyProtocol <NSObject>
- (void) register:(MyProtocolCB*) cb;
@end

I'm receiving this syntax error: error: expected type-specifier before 'MyProtocolCB'

Upvotes: 21

Views: 6097

Answers (2)

AFTAB MUHAMMED KHAN
AFTAB MUHAMMED KHAN

Reputation: 2186

use id instead of NSObject as you already know id is the instance type or generic type so if you use id it will help you in big perspective.

- (void) register:(id<MyProtocol>*) sender;

Upvotes: 0

Vladimir
Vladimir

Reputation: 170839

Try:

- (void) register:(NSObject<MyProtocol>*) cb;

Upvotes: 51

Related Questions