@protocol Runnable
- (id<Runnable>) works; //this compiles fine
- (Runnable *) broke; // get a compile error saying Expected ')' before 'Runnable'
@end
I’m not sure I understand why xCode complains about the - (Runnable *) broke; line
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Protocols in Obj-C don’t look syntactically like, say, “interfaces” in Java, where the syntax for interface pointers and subclass pointers are essentially the same.
The
id<Runnable>is the idiomatic way that you say “an object that conforms toRunnable. Anidis a reference to any type of object, and the<>notation expresses an explicit conformance to a given protocol for the purposes of type checking.If you say
Foo *, you’re referring to an object of either typeFooor one of its subclasses.This just happens to be the Obj-C syntax for this. With this syntax, the semantics are similar to what you’d get in, e.g. Java.