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: Ben Dougall <email@hidden>
- Date: Tue, 27 May 2003 14:14:13 +0100
On Tuesday, May 27, 2003, at 03:57 am, Wade Tregaskis wrote:
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.
ok, thanks. is there ever a time that you can get away with just
alloc-ing an object, and not init-ing it? and continue as usual?
_______________________________________________
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.