Objective-c – In Objective-C why is id used as return type for init methods

objective c

I did some quick searching and couldn't find an answer for this.

I'm interested to know why in Objective-C, id is used as the return type for init methods.

My guess is that it's because if the class is overridden, you don't want to return an object of the superclass's type, but I'm interested to know if it's done for some other reason.

Best Answer

Yup. Your idea is right on the money. A subclass should still be able to use its superclass's initialization methods and return its own type instead of the super type and returning id allows it to do that.