Chapter 10

Object Initialization

So far, we’ve created new objects in two different ways. The first way is [SomeClass new], and the second is [[SomeClass alloc] init]. These two techniques are equivalent, but the common Cocoa convention is to use alloc and init rather than new. Typically, Cocoa programmers use new as training wheels until they have enough background to be comfortable with alloc and init. It’s time for your training wheels to come off.

Allocating Objects

Allocation is the process by which a new object is born. It’s the happy time when a chunk of memory is obtained from the operating system and designated as the location that will hold the object’s instance variables. Sending the alloc message to a class causes that class to ...

Get Learn Objective-C on the Mac: For OS X and iOS, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.