您的位置:首页 > 其它

OC self注意事项

2015-12-10 14:25 337 查看
#import <Foundation/Foundation.h>

@interface Person : NSObject
- (void)test;
+ (void)test;

- (void)test1;
+ (void)test2;

- (void)haha1;

+ (void)haha2;

@end

@implementation Person
- (void)test
{
NSLog(@"调用了-test方法");

// 会引发死循环
//[self test];
}

+ (void)test
{
NSLog(@"调用了+test方法");

// 会引发死循环
//[self test];
}

- (void)test1
{
[self test]; // -test
}

+ (void)test2
{
[self test]; // +test
}

- (void)haha1
{
NSLog(@"haha1-----");
}

void haha3()
{

}

+ (void)haha2
{
// haha3();
[self haha3];
// [self haha1];
}
@end

int main()
{
[Person haha2];
//Person *p = [Person new];

//[p test1];
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: