Re: The Unadopted Protocol
Re: The Unadopted Protocol
- Subject: Re: The Unadopted Protocol
- From: John Johnson <email@hidden>
- Date: Wed, 2 Jun 2010 11:09:24 -0500
> This compiles and runs fine, even though MyClass never adopted the protocol
> Unadopted. It take it that by casting mc to an id, I cause the compiler to
> grasp at the only signature for "testing" that it knows about, namely the
> one in the protocol. So it happily uses that signature without complaint,
> and at runtime the correct message is sent to the MyClass instance.
I noticed this, but I assume that by casting it to an id you are discarding the protocol conformance. I'd always thought protocol conformance was just to have the compiler warn you if you hadn't implemented a particular method. Doesn't it only get checked at runtime if conformsToProtocol: is called on it?
By having an id variable, the compiler thinks it can accept any message, and if the object can respond to that message at runtime, it's all fine.
So... maybe (d) :)
_______________________________________________
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