In article <wcyeo-B4F390.20591423052008@[EMAIL PROTECTED]
>,
William Yeo <wcyeo@[EMAIL PROTECTED]
> wrote:
> In article <65idnaQoP5TqFKrVnZ2dnUVZ_uqdnZ2d@[EMAIL PROTECTED]
>,
> Don Bruder <dakidd@[EMAIL PROTECTED]
> wrote:
>
> OK, let's concentrate one one part at a time. You need to grok the
> allocation and initiaization stages of object creation before anything
> else will make sense. Otherwise all your objects will self-destruct at
> random times (been there, done that, got the T-****rt :-)
>
> Allocation and initialization first.
>
> > > You really want [[MyButton alloc] init] instead.
> >
> > But... Wait a minute...
> >
> > If I do that, I've got to have an "alloc" in the "MyButton" class, no?
> > Or does that feed back up the chain to whatever class (probably
> > "NSObject"?) it is that "knows how" to alloc?
>
> If you don't supply one, it'll use the ancestor's version ... it's OOP -
> remember. The basic alloc method allocates enough storage for all of the
> data members in your object plus all of the data members in your
> object's ancestors.
<light bulb>
Which means I don't need to write an "alloc" of my own... Hooray! And
further, that "de-fogs" some of the confusion I've been having. NOW I
think I've got it. (Remind me to set up an appointment at the clinic - I
hear that these days, they've got pills that'll cure "it" in about 2
weeks :) )
> > > It seems that if that's the case, I'd be getting back an object of
> > whatever-class-it-was-that-said-"I know how to alloc", rather than a
> > "MyButton"??? How does that object know how to init a "MyButton"???
>
>
> > > If you need to customize the initialization of your instances, you
> > > provide an implementation for -init for that class. Within that
> > > implementation, you will invoke some [super init...] variant.
> >
> > Fair enough, and noted for future, but once again the answer I got
seems
> > to "go around" the question I asked.
> >
> > Which "init" am I invoking when I do "[[super alloc] init]"? Am I
> > invoking "super"'s init? The init of the object I just alloced?
>
> You are not listening.
Trust me... I'm listening. But so far, I haven't heard the answer - Or
if I have, it's come through garbled enough that I haven't been able to
recognize it as BEING the answer.
> Consider [[MyObject alloc] init]
>
> This uses [MyObject alloc] to create an instance (of type MyObject) and
> allocate storage space for the data (contained in an MyObject instance).
> Once that has been done the [... init] is your chance to initialize the
> data.
<light bulb redux>
Which, in combination with the first light bulb, means that the
"- (MyObject *)init" method in the MyObject class is the "init" that
runs...
<headsmack>
Hmmm... Methinks this is one of those epiphany things, no?
I think I've got that part, now. But it would have been quicker if
someone had just said "The init that runs is the init in the class of
the object that you just alloc-ed", which is what I've been trying to
figure out all along. Up to now, I've been under the impression - now
clearly wrong - that the super's init was the one that was being
invoked. Now that I've made the connection, it's fairly obvious.
Thanks. That's going to make things a bit smoother, I'm thinking.
'Scuse me whilst I go edit accordingly... This might take a while...
--
Don Bruder - dakidd@[EMAIL PROTECTED]
- If your "From:" address isn't on my
whitelist,
or the subject of the message doesn't contain the exact text
"PopperAndShadow"
somewhere, any message sent to this address will go in the garbage without
my
ever knowing it arrived. Sorry... <http://www.sonic.net/~dakidd>
for more
info


|