Re: State of instance variables defined at instantiation?
Re: State of instance variables defined at instantiation?
- Subject: Re: State of instance variables defined at instantiation?
- From: Wade Tregaskis <email@hidden>
- Date: Tue, 27 May 2003 12:57:47 +1000
I've checked my Cocoa book, the list archives etc, and I want to
know: Is the state of instance variables inside an object defined at
instantiation time?
from what i know it actually occurs during alloc, so occurs before
init. what i'd like to know is if you want all internal variables set
to 0, is init necessary? what else does init do, if anything other
than set variables up?
Well, it's created a dependency for itself through it's own existence.
When you create an object using a generic allocation routine (e.g.
alloc) you should call at the very least it's generic 'init' method, to
allow it to set up any non-nil parameters, or perform any other
appropriate instantiation.
Unfortunately, the result is that if you don't define a generic init
method, and someone using the class tries to do the nice thing and call
[[yourClass alloc] init], they'll get thrown a compiler warning. So
you have to define a useless init method, like the following:
- (object*)init {
return (self = [super init]);
}
This is only a problem if you don't provide other init methods. In
such a case, the user should probably be using them anyway, and so the
lack of a generic init method would be unimportant.
Wade Tregaskis
-- Sed quis custodiet ipsos custodes?
_______________________________________________
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.