Re: The Unadopted Protocol
Re: The Unadopted Protocol
- Subject: Re: The Unadopted Protocol
- From: Matt Neuburg <email@hidden>
- Date: Sat, 05 Jun 2010 09:40:19 -0700
- Thread-topic: The Unadopted Protocol
On or about 6/2/10 11:11 AM, thus spake "Greg Parker" <email@hidden>:
> 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.
But in fact I see now that UIAlertView works exactly this way; its delegate
is typed as id, not as id <UIAlertViewDelegate>. This explains why my class
never has to adopt UIAlertViewDelegate formally. Doubtless an alert view
with a delegate is *so* common that Apple felt it would drive the programmer
mad to have to adopt UIAlertViewDelegate formally all over the place.
m.
--
matt neuburg, phd = email@hidden, http://www.tidbits.com/matt/
pantes anthropoi tou eidenai oregontai phusei
Among the 2007 MacTech Top 25, http://tinyurl.com/2rh4pf
AppleScript: the Definitive Guide, 2nd edition
http://www.tidbits.com/matt/default.html#applescriptthings
Take Control of Exploring & Customizing Snow Leopard
http://tinyurl.com/kufyy8
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
TidBITS, Mac news and reviews since 1990, http://www.tidbits.com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden