I understand pointers pretty well (I seriously never thought I would say that), but I am curious about something.

Why don’t we use pointers to C type instance variables?

So instead of this:

@interface Employee : Person { int employeeID; NSString *lastName; Person *spouse; NSMutableArray *children; }
couldn’t we do:

@interface Employee : Person { int *employeeID; NSString *lastName; Person *spouse; NSMutableArray *children; }

Is it just because that is the C way to do things or is there some other reason that might appease my curious mind?


You certainly could use pointers, but then you’d lose the ability to let Xcode generate your getters and setters (unless your other classes are going to pass along pointers, which isn’t typical).

If you call [person setAge:8], no one would blink an eye, but this would be awkward at best:

int age = 8;
[person setAge:&age];

Plus memory management comes into play; it’s possible that ARC just makes this work without thinking about it, but I imagine there’s going to be something you’ll have to manage.