Return to Snippet

Revision: 53637
at November 30, 2011 07:14 by codeRefiner


Initial Code
In summary, this is what an init method needs to do:

- Call [super init] and assign the result to self.
- Check whether self is nil. If so, then exit this method right away and return nil to the caller.

- If self was not nil, do additional initialization if necessary. Usually this means you give properties and instance variables their initial values. By default, objects are nil, ints are 0 and BOOLs are NO. If you want to give these variables different initial values, then this is the place to do so.
- Return self to the caller.

You don’t always need to provide an init method. If your init method doesn’t need to do anything — if there are no properties or instance variables to fill in — then you can leave it out completely and the compiler will provide one for you.

Initial URL


Initial Description
Here is a breakdown of creating a custom initializer and or general rules of init

Initial Title
A note about init methods

Initial Tags
iphone

Initial Language
iPhone