是的,同样适用;对象指针是一个变量,就像浮点数一样:
测试.m:
#include <Foundation/Foundation.h>
@interface Foo : NSObject
{
NSString *ivarString;
}
- (void)foo;
- (void)test;
@end
@implementation Foo
- (void)foo
{
NSString *stackString;
NSLog(@"stackString='%@', ivarString='%@'", stackString, ivarString);
stackString = @"Hello";
ivarString = @"World";
}
- (void)test
{
[self foo];
[self foo];
}
@end
int main(int argc, const char **argv)
{
@autoreleasepool
{
Foo *foo = [[[Foo alloc] init] autorelease];
[foo test];
}
return 0;
}
输出:
2012-08-06 06:52:36.123 test[15293:403] stackString='(null)', ivarString='(null)'
2012-08-06 06:52:36.126 test[15293:403] stackString='Hello', ivarString='World'
请注意,此测试项目使用 MRR,而不是 ARC。