Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: subclassing NSArrayController



mmalcolm crawford, email@hidden, wrote:
>Every class has a designated initialiser.
>In the absence of other initialisation methods, it is init.

It is my understanding designated initializer is mere convention. For
example, I believe this poorly written class does *not* have a designated
initializer:

@interface NoDesignatedInitializer : NSObject {
NSString *_name;
int _age;
}
- (id)initWithName:(NSString*)aName;
- (id)initWithAge:(int)anAge;
@end

//--

@implementation NoDesignatedInitializer
- (id)initWithName:(NSString*)aName {
self = [super init];
if( self ) {
_name = [aName retain];
_age = -1;
}
return self;
}

- (id)initWithAge:(int)anAge {
self = [super init];
if( self ) {
_name = @"invalid";
_age = anAge;
}
return self;
}
@end

Yes, -initWithName and -initWithAge *should* call thru to an
-initWithNameAndAge designated initializer. But it doesn't.

Perhaps I misunderstand your definition of "designated initializer". For
example, your 'initializer' has an 's' in it for some strange reason ;-)

| Jonathan 'Wolf' Rentzsch http://rentzsch.com
| Red Shed Software http://redshed.net
| "better" necessarily means "different"
_______________________________________________
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.




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.