Tom Hamming
Tom Hamming

Reputation: 10981

Why does initWithCoder not return instancetype?

It seems that most init methods in Objective-C now tend to return instancetype instead of id. See [UIView initWithFrame:], [UIViewController initWithNibName:bundle:], [NSArray init] and siblings, etc. But initWithCoder uses id. Why is this? Has it just not been updated yet? Or is there a reason it has to be id?

Upvotes: 0

Views: 627

Answers (1)

Teja Nandamuri
Teja Nandamuri

Reputation: 11201

It is not updated yet. You can still code it with instance type.

     - (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        //...
    }
    return self;
}

Upvotes: 1

Related Questions