Objective-C指针的使用 [英] Objective-C use of pointers

查看:92
本文介绍了Objective-C指针的使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

何时以及何时不需要*符号(这是因为在Objective-C中,所有类似NSString的变量都是指针变量)?

When do you and when dont you need the * symbol (which is because in objective-c all variables like NSString are pointer variables)?

例如,何时需要执行"NSString *"而不是"NSString"?

For example when do you need to do "NSString *" instead of just "NSString"?

推荐答案

在Objective-C中,所有对象引用都是指针,因此在使用Objective-C对象进行声明时,始终需要使用指针运算符.

In Objective-C, all object references are pointers, so you always need the pointer operator when you declare with an Objective-C object.

对于其他类型,其用法与C中的用法完全相同.当您想通过引用传递数据结构或原始类型时,请使用指针.

For other types, the use is exactly the same as in C. Use pointers when you want to pass data structures or primitive types by reference.

这篇关于Objective-C指针的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆