iOS engineer who likes clean, simple designs and sans-serif.

Loading

Week 2 Day 1 – Custom or Designated Initializer

Here’s the Objective-C code that I like to start with in order to write custom or designated initializers.

- (instancetype)init
{
    self = [super init];
    if (self) {
       // Custom init here
    }
    return self;
}

For a designated initializer, since it’s the most complicated initializer, call it from all the others.

- (instancetype)init
    return [self initWithOption:@"customOption"];
}

- (instancetype)initWithOption:(NSString *)option
{
    self = [super init];
    if (self) {
       // Custom init here
    }
    return self;
}

Leave a Comment