Re: Adding a category to a protocol
Re: Adding a category to a protocol
- Subject: Re: Adding a category to a protocol
- From: Ed Baskerville <email@hidden>
- Date: Sun, 6 Mar 2005 02:34:01 -0800
The simple answer, I believe, is no: categories are for classes.
Longer answer: categories are a set of methods *and their
implementations* used to extend an existing *class*. A category can
easily depend on the implementation, not just the interface, of a
class, so they are not, conceptually or otherwise, OK for extending
protocols.
Longest and most useful answer: you could certainly accomplish
something like this by creating an informal protocol, i.e., a category
on NSObject, which is available to every class that inherits from
NSObject, i.e., all of them. If your category really only depends on
the classes having implemented a particular protocol, you can just make
sure you only use the methods in the category on objects that implement
the protocol. Use NSObject's conformsToProtocol: method in the calling
code for verification, and also in the implementation of the category
itself, and throw an exception if you try to use it on a non-conforming
object.
--Ed
On Mar 5, 2005, at 10:32 PM, Rosyna wrote:
Is it at all possible to make a category on a protocol?
Say I want to say that all objects conforming to MyProtocol now also
respond to the methods defined in MyCategory. The reason for wanting
to do it on a protocol is because the category depends on the object
conforming to MyProtocol.
--
Sincerely,
Rosyna Keller
Technical Support/Holy Knight/Always needs a hug
Unsanity: Unsane Tools for Insanely Great People
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden