• 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: Convenience methods and classes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Convenience methods and classes


  • Subject: Re: Convenience methods and classes
  • From: Greg Titus <email@hidden>
  • Date: Thu, 31 Jan 2002 11:23:39 -0800

Hi Drew,

On Thursday, January 31, 2002, at 11:02 AM, Drew McCormack wrote:
I want to write a convenience constructor, but can't figure out how I can access the Class instance from within the class method. For example, if I want to write a method "+expression" which allocates and initializes an "Expression", how do I allocate the expression in the method?
Can I just do this
[self alloc]

Yes, you can. When you call a class method "self" is the class. "[self alloc]" will work great.

Probably not.
Or do I have to rewrite the method for every subclass of Expression I write, doing this
[SubExpression alloc]

I sure hope the latter is not right. I must be able to inherit the class method, right?

Yep. This is one of the major differences (and advantages) of Objective-C compares to Java or C++ (neither of which have real inheritable class methods.)

Hope this helps,
-Greg


References: 
 >Convenience methods and classes (From: Drew McCormack <email@hidden>)

  • Prev by Date: Re: System contextual menus
  • Next by Date: <no subject>
  • Previous by thread: Convenience methods and classes
  • Next by thread: Re: Convenience methods and classes
  • Index(es):
    • Date
    • Thread