Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
You want to create an instance of a new object, but you don’t understand the difference between allocation and initialization and why you should have to both allocate and initialize an object before you can use it.
You must both allocate and initialize an object before using it.
An object can be allocated using the alloc instance
method. This class method will allocate memory to hold the object and
its instance variables and methods. However, allocation leaves memory
undefined. So in addition, each object must be
initialized, which sets the values of its data.
One initialization method must be the designated initializer, which is
normally the initialization method with the most parameters. For
instance, the initWithFrame: method
is the designated initializer of objects of type UIView. Always allocate and initialize your
objects, in that order, before using them.