On Jun 2, 2010, at 8:57 AM, Matt Neuburg wrote:
> So this appears to be a technique for implementing a highly informal
> protocol. (The technique is: define a protocol, don't bother adopting it
> anywhere, but send messages defined in that protocol to an id.)

Yep. When the compiler looks for a method declaration matching a message sent 
to `id`, it looks at every declaration encountered up to that point in the file.

That's comparable to the traditional way to create informal protocols: declare 
a category on NSObject, don't bother implementing it anywhere, and send 
messages declared in that category to other objects.

In general we discourage both of these now. The problem is that somebody 
somewhere is likely to declare a method with the same name but different 
parameter types. In these cases - message to `id` and category on NSObject - 
the compiler has no way to know which declaration to use. If it guesses wrong, 
your code may be doomed.


-- 
Greg Parker     [email protected]     Runtime Wrangler


_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to