对象方法利用"self->成员变量名"访问当前对象内部的成员变量
#import <Foundation/Foundation.h>
@interface Person : NSObject
{
int _age;
}
- (void)test1;
- (void)test2;
@end
@implementation Person
- (void)test1
{
_age = 20;
[self test2];
}
- (void)test2
{
int _age = 10;
NSLog(@"调用了-test2方法-%d", self->_age);
}
@end
int main()
{
Person *p = [Person new];
[p test1];
return 0;
}
//输出:调用了-test2方法-20 |
|