Using Instances

In order to use an instance of a class (an object), you must have a variable that points to the object. A pointer variable stores the location of an object in memory, not the object itself. (It points to the object.) A variable that points to an object is declared like so:

P​a​r​t​y​ ​*​p​a​r​t​y​I​n​s​t​a​n​c​e​;​

This variable is named partyInstance. It is meant to be a pointer to an instance of the class Party. However, this does not create a Party instance – only a variable that can point to a Party object.

Creating objects

An object has a life span: it is created, sent messages, and then destroyed when it is no longer needed.

To create an object, you send an alloc message to a class. In response, the class creates an ...

Get iOS Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.