• 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
Categories and adding instance variables
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Categories and adding instance variables


  • Subject: Categories and adding instance variables
  • From: Kay Roepke <email@hidden>
  • Date: Sun, 1 Aug 2004 19:27:27 +0200

Yes, I know it doesn't work. I know about subclassing.

Now that I said that ;-), here's my question:

Is there a technical reason that you cannot add instance variables to class using categories?
Or is it just convenient for the runtime?

I have this generated class, lets call it Lexer. It inherits from Scanner, which is part of an existing framework.
While generating Lexer's source code, I also end up with a enum containing the tokens to be produced by Lexer.

Of course I could simply add this enum to the Lexer class and be done with it, but guess what:
I have a Parser class which wants the very same enum, in order to know which tokens it must
handle. Obviously, I don't want that enum to be duplicated in my (albeit generated) code for
hygenical reasons.
In the C++ version this is done via multiple inheritance and in Java one could simply make an
interface for this. ObjC on the other hand craps out.

Does anyone have a suggestion how this could be cleanly done?
One thing I came up with would be to use a static dictionary and get the tokens from there, but that
seems like overkill to me.

Thanks,

Kay
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Categories and adding instance variables
      • From: Brent Gulanowski <email@hidden>
    • Re: Categories and adding instance variables
      • From: "Dennis C. De Mars" <email@hidden>
  • Prev by Date: Re: Non-contiguous selections in NSTextView
  • Next by Date: Re: Find panel
  • Previous by thread: NSDateFormatter, Interface Builder, and System Preference date formats
  • Next by thread: Re: Categories and adding instance variables
  • Index(es):
    • Date
    • Thread