Objective c obj-c中标题中变量声明中的星号

Objective c obj-c中标题中变量声明中的星号,objective-c,pointers,variables,Objective C,Pointers,Variables,我知道asterix是指针的,我现在理解指针了。但我仍然不确定为什么在标题中声明变量时需要使用asterix,例如: UINavigationController * navController; 为什么不是: UINavigationController navController; 谢谢,因为在你的例子中: UINavigationController * navController; UINavigationController*导航控制器 navController是指向UINav

我知道asterix是指针的,我现在理解指针了。但我仍然不确定为什么在标题中声明变量时需要使用asterix,例如:

UINavigationController * navController;
为什么不是:

UINavigationController navController;

谢谢,因为在你的例子中:

UINavigationController * navController;
UINavigationController*导航控制器

navController是指向UINavigationController类型的对象的指针

在创建新实例时,始终使用Objective-C对象处理指针:

[[MyClass alloc] init] 

它返回指向新创建的MyClass类型对象的指针,即(MyClass*)

,因为在您的示例中:

UINavigationController * navController;
UINavigationController*导航控制器

navController是指向UINavigationController类型的对象的指针

在创建新实例时,始终使用Objective-C对象处理指针:

[[MyClass alloc] init] 

它返回指向新创建的MyClass类型对象的指针,即(MyClass*)

在您声明需要为对象分配的内存的头中。您需要使用
*
运算符,因为您只想为指向对象的引用/指针声明内存空间,而不是为对象本身声明空间。

在标头中,您要声明需要为对象分配的内存。您需要使用
*
操作符,因为您只想为指向对象的引用/指针声明内存空间,而不是为对象本身声明空间