OC self注意事项

 1 #import <Foundation/Foundation.h>
 2 
 3 @interface Person : NSObject
 4 - (void)test;
 5 + (void)test;
 6 
 7 - (void)test1;
 8 + (void)test2;
 9 
10 
11 - (void)haha1;
12 
13 + (void)haha2;
14 
15 
16 @end
17 
18 @implementation Person
19 - (void)test
20 {
21     NSLog(@"调用了-test方法");
22     
23     // 会引发死循环
24     //[self test];
25 }
26 
27 + (void)test
28 {
29     NSLog(@"调用了+test方法");
30     
31     // 会引发死循环
32     //[self test];
33 }
34 
35 - (void)test1
36 {
37     [self test]; // -test
38 }
39 
40 + (void)test2
41 {
42     [self test]; // +test
43 }
44 
45 - (void)haha1
46 {
47     NSLog(@"haha1-----");
48 }
49 
50 
51 void haha3()
52 {
53     
54 }
55 
56 + (void)haha2
57 {
58     // haha3();
59     [self haha3];
60     // [self haha1];
61 }
62 @end
63 
64 int main()
65 {
66     [Person haha2];
67     //Person *p = [Person new];
68     
69     //[p test1];
70     return 0;
71 }
原文地址:https://www.cnblogs.com/oc-bowen/p/5035928.html