• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Adding a category to a protocol
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
References: 
 >Adding a category to a protocol (From: Rosyna <email@hidden>)

  • Prev by Date: Re: NSTask outliving parent
  • Next by Date: Re: How to make key shortcuts and mouse click trigger controlTextDidEndEditing:
  • Previous by thread: Adding a category to a protocol
  • Next by thread: header files in application bundle
  • Index(es):
    • Date
    • Thread