Designated initializers


#1

The book (and some online resources) pretty much describes designated initializers as a language feature, but this made me scratch my head, since I don’t see how the compiler would know which initializer is the designated one (calling [super init] or having a certain number of parameters may not be a unique differentiator).

So I came to the conclusion that designated initializers are a convention, not a language feature. This is an important distinction, IMHO. I was looking for preprocessing directives or… something. Now that I think about it, I’m not sure what the compiler would do with that information :slight_smile: . But I think it would be helpful if the book spelled out that distinction - I’m not sure why, but my brains were very insistent on figuring that one out.

Thanks!

D. -


#2

Hello,

I see what you mean, and while i believe yes it is a convention, but it is a language feature that allows you to do so.

If there wasn’t a language feature and different syntaxes that supported the use of designated initializers, simply making it a convention would not make it viable. Maybe this is what the authors mean.

But i see why you scratch your head, made me do the same a little when i read your post lol :slight_smile:

Hope i helped.
Best Regards
/JBJ
Follow me on - www.jbjprogramming.com


#3

Yes, designated initializers are a convention. However, the use of the word “init” is a language feature, because it adds certain properties to the arguments and the implicit variable self. (init being a language feature is new to iOS 5.0 and ARC).


#4

Is there a convention or rule of thumb for identifying or even marking designated initializers in code or are you just suppose to “know” or it is it just obvious for classes that you are subclassing? I would guess the init method with the most parameters would be a good rule of thumb to go on.