/ Published in: iPhone
Here is a breakdown of creating a custom initializer and or general rules of init
- 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.
You need to login to post a comment.