I’m trying to write something similar to this (sorry if the sample is not 100% correct, im just writing off the top of me head):
interface Handler
{
void doSomething ( );
}
otherclass
{
void othermethod ( Handler handler )
{
// Handler do something
}
}
So in ObjectiveC I made the following:
@protocol Handler
- (void) doSomething;
@end
// Other class
- (void) othermethod: (Handler*) handler
{
// Do something
}
But I get the following error on the othermethod declaration line:
Expected ‘)’ before hander.
I know there is no syntax error here (I can replace Handler* with NSObject* and the error goes away), so obviously my use of a protocol in this case is incorrect.
Could anyone point me to the proper way of creating a C# like interface?
You want to use a type like this:
This means “any object (type
id) that implements theHandlerprotocol”. The protocol goes in between the greater than/less than signs. You can also use a declaration likeNSObject <Handler> *obj, which means “any object of typeNSObjector a subclass that implements theHandlerprotocol”.You can also declare an object that implements several protocols like so: