Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Chapter 11 - init method

Hey all,

I was just curious about the init method on p. 240.  There is no return type declared, yet it returns self.  Everything works fine, so I'm wondering if this is a special case for init messages, or if there is no return type specified, the compiler automatically assumes (id) ?



  • Hi Bob:

    init is declared on the NSObject class, and so it's inherited from there. NSObject declares it with an explicit return parameter, as:

    - (id) init;

    Your supposition that if the return type is unspecified then the compiler assumes id is correct. I think this comes from Obj-c's SmallTalk heritage.
  • Hey Thanks! and thanks for writing such a great book!  Of all the books I've been reading about Cocoa and ObjC programming, this is the one I always come back to.
Sign In or Register to comment.