Question

I don't know what does this mean?I think this is related to protocol,but can someone tell me what is the correct meaning of this kind of syntax?

id<aKeypadDelegate> delegate;
Was it helpful?

Solution

id is a reference to a Objective-C object whose class is unknown, hence delegate can be any Objective-C object. When you find this:

@property (nonatomic, weak) id<SomeProtocolHere> delegate;

...it means that delegate can be any kind of Objective-C object that implements ("conforms to") SomeProtocolHere protocol.

OTHER TIPS

hmm, you edited your question so my answer is totally different... I've rewritten it.

id means "any object". It's just a number pointing to a particular piece of RAM.

id<Foobar> means "any object conforming to the Foobar protocol".

A protocol defines a list of methods that an object must have.

Beware protocols are only checked at compile time, they're not checked at runtime. While the code is actually executing it doesn't do any checks to see what exists at the specified RAM location. Not all mistakes will be caught by the compiler.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top