Re: Convenience methods and classes
Re: Convenience methods and classes
- Subject: Re: Convenience methods and classes
- From: Ondra Cada <email@hidden>
- Date: Thu, 31 Jan 2002 22:13:27 +0100
Drew,
>
>>>>> Drew McCormack (DMC) wrote at Thu, 31 Jan 2002 20:02:55 +0100:
DMC> I want to write a convenience constructor, but can't figure out how I
DMC> can access the Class instance from within the class method. For example,
DMC> if I want to write a method "+expression" which allocates and
DMC> initializes an "Expression", how do I allocate the expression in the
DMC> method? Can I just do this
DMC> [self alloc]
DMC>
DMC> Probably not.
Yep, that's the way. Why not?
The generic pattern of (almost) all convenience constructors is pretty simple:
+(SomeClass)someClassWithBlah:foo blah:bar ... {
return [[[self alloc] initWithBlah:foo blah:bar ...] autorelease];
}
Quite seldom you need more.
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
2K Development: email@hidden
http://www.2kdevelopment.cz
private email@hidden
http://www.ocs.cz/oc