在Objective-C中使用指针? [英] Using Pointers in Objective-C?
问题描述
每当Apple创建自己的自定义类时,它通常会创建一个指向对象的指针,而不是实际对象本身.
Whenever Apple creates its own custom classes, it often creates a pointer to the object instead of the actual object itself.
例如,不要这样做:
Class object
他们经常这样做:
Class *object = [[Class alloc] init];
为什么经常使用指针而不是将对象放在堆栈上?是否出于某种技术原因,因为我认为这样做没有任何直接好处.
Why are pointers so commonly used instead of putting the object on the stack? Is there some technical reason for this, because I don't see any immediate benefit of doing so.
如果Objective-C不支持堆栈上的对象,它们如何创建任何非指针?我的意思是我已经看到人们直接使用NSInteger.
If Objective-C doesn't support objects on the stack how can they create any non-pointers? I mean I have seen people use NSInteger directly.
推荐答案
Objective-C不支持堆栈中的对象.
Objective-C doesn't support objects on the stack.
Fantastic explanation on Mike Ash's blog here
这篇关于在Objective-C中使用指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!