views:

30

answers:

2

I get that asterix is for pointers, and I understand about pointers now. But I'm still not sure why when declaring a variable in a header I need to use an asterix, for example:

UINavigationController * navController;

why isn't that:

UINavigationController navController;

Thanks

+2  A: 

Because in your example:

UINavigationController * navController;

navController is a pointer to object of UINavigationController type;

and you always work with pointers using Objective-C objects, when you create new instance with:

[[MyClass alloc] init] 

it returns pointer to newly created object of type MyClass i.e (MyClass *)

Vladimir
+1  A: 

In the header you are declaring the memory that needs to be allocated for an object. You need to use the * operator because you only want to declare memory space for a reference/pointer to the object, and not space for the object itself.

Tom