Suraj K Thomas
Suraj K Thomas

Reputation: 5883

id<>delegate what is the meaning of this syntax?

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;

Upvotes: 0

Views: 166

Answers (2)

Matteo Pacini
Matteo Pacini

Reputation: 22846

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.

Upvotes: 2

Abhi Beckert
Abhi Beckert

Reputation: 33369

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.

Upvotes: 1

Related Questions