Re: Method not seeing array as array
Re: Method not seeing array as array
- Subject: Re: Method not seeing array as array
- From: Evan Schoenberg <email@hidden>
- Date: Thu, 3 Feb 2005 18:33:03 -0600
Using self = [super init] allows for the possibility that a superclass
somewhere along the hierarchy returns or will later in development
return an object which may not be same as the alloc / allocWithZone:...
I've been bitten by that before. For example, if you subclass
NSMutableSet, if you just do [super init] rather than self = [super
init] you are going to be returning the wrong object in many cases.
-Evan
On Feb 3, 2005, at 5:49 AM, Marco Scheurer wrote:
When you inherit from a class, you usually know what super will do,
and it is not necessary to blindly use "defensive programming" and
test against everything. When inheriting from NSObject, how could init
return anything else than self?
There's a good reason to write:
self = [super init];
and that's because init returns an object, so we may just as well use
it rather than documenting the fact that we don't care by writing:
(void) [super init];
Other than that, it is not necessary in that case. Also, the value
returned by NSObject's init can not be nil, so I usually don't put
that test in my code.
No flame, please, all this is an opinion and a matter of taste. I know
that the doc says "Programs should therefore always use the object
returned by init, and not necessarily the one returned by alloc or
allocWithZone:, in subsequent code."...
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden