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;
有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top