Reading the source code, I've noticed the following (CHListStack.m):
- (id) init {
if ((self = [super init]) == nil) return nil;
list = [[CHSinglyLinkedList alloc] init];
return self;
}
- (id) initWithArray:(NSArray*)anArray {
if ([self init] == nil) return nil;
for (id anObject in anArray) {
[list prependObject:anObject];
}
return self;
}
According to this code the designated initializer is (-init) while (-initWithArray:) is the convenience one. So, shouldn't it be on the contrary? (-init) will be convenience initializer that will supply a default parameter to (-initWithArray:) that will be a designated initializer?
Apple Documentation states "The initializer of a class that takes the full complement of initialization parameters is usually the designated initializer". The reason I've created this issue is that the current designated-convenience initializers scheme may be confusing to some developers.
So, that code may be converted into this one:
// Convenience initializer
- (id) init {
return [self initWithArray:nil];
}
// Designated initializer
- (id) initWithArray:(NSArray*)anArray {
if ((self = [super init]) == nil) return nil;
list = [[CHSinglyLinkedList alloc] init];
for (id anObject in anArray) {
[list prependObject:anObject];
}
return self;
}
Reading the source code, I've noticed the following (CHListStack.m):
According to this code the designated initializer is (-init) while (-initWithArray:) is the convenience one. So, shouldn't it be on the contrary? (-init) will be convenience initializer that will supply a default parameter to (-initWithArray:) that will be a designated initializer?
Apple Documentation states "The initializer of a class that takes the full complement of initialization parameters is usually the designated initializer". The reason I've created this issue is that the current designated-convenience initializers scheme may be confusing to some developers.
So, that code may be converted into this one: