Why is the init
method not a class method? I mean init
's method body starts with an -
.
Methods starting with -
are instance methods as far as I know, but obviously we want to create an instance.
Asked
Active
Viewed 227 times
1
-
`init` is not a [factory method](http://en.wikipedia.org/wiki/Factory_method_pattern) - it's the [constructor](http://en.wikipedia.org/wiki/Constructor_%28object-oriented_programming%29) for an instance. – Jay Apr 01 '13 at 07:20
1 Answers
9
init
is not for creating an instance; that's alloc
's job (and alloc
is a class method).
init
is for setting up the created instance. It needs access to the new instance's ivars, and must be an instance method.

jscs
- 63,694
- 13
- 151
- 195
-
Another installment of [bikeshedding](http://meta.stackexchange.com/questions/31253/the-bike-shed-problem-and-so). I wish upvotes were actually proportional to effort. – jscs Mar 31 '13 at 22:32
-
Oh, sorry, @methanol; I forgot you would be notified of that comment. I was addressing anyone else who came by and felt compelled to vote. No, I meant that I should have gotten _fewer_. This answer took me less than a minute to type out, and I don't feel like it's worth seven upvotes. – jscs Mar 31 '13 at 23:53
-
the upvotes are not directly proportional to the quality of answer, but quality of person who posted it. So here your comes into play. :) – Anoop Vaidya Apr 01 '13 at 07:28
-
@AnoopVaidya: That's exactly how it's _not_ supposed to be. More reputation shouldn't lead directly to more reputation. Votes are about the content, not the person. – jscs Apr 01 '13 at 15:49
-
In meta I read about excess voting to celebrities, even on wrong answers they(John Skeet) got +5 votes :D – Anoop Vaidya Apr 01 '13 at 17:03
-
@AnoopVaidya: Yes, that's also a problem; not really anything that can be done about it, though. – jscs Apr 01 '13 at 17:05
-
A click isnt that much effort. In fact its a nice touch nothing more. Dont take it too serious. Your life probably wont be better with more online reputation ;-) – tuna Apr 02 '13 at 09:05