f(sixleaves) = sixleaves

重剑无锋 大巧不工

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  95 随笔 :: 0 文章 :: 7 评论 :: 0 Trackbacks
 1 #import <Foundation/Foundation.h>
 2 
 3 @interface Person : NSObject
 4 + (void)test;
 5 - (void)test;
 6 @end
 7 
 8 @implementation Person
 9 + (void)test
10 {
11     NSLog(@"Class Method test");
12 }
13 - (void)test
14 {
15     NSLog(@"Instance Method test");
16 }
17 
18 - (void)fuck
19 {
20     NSLog(@"Instance Method fuck");
21 }
22 @end
23 
24 int main() {
25     
26     Person *p = [Person new];
27     //[p test];  unrecognized selector sent to instance 0x7f9c11c10600
28     [Person test];
29     
30     // [Person fuck];  unrecognized selector sent to class 0x10a1f71c0
31     [p fuck];
32     return 0;
33 }
34 
35 // 总结OC中类方法与对象方法的区别
36 /*
37  1.对象方法一减号开头。类方法以加号开头
38  2.对象方法只能有对象调用。类方法只能由类调用,否则运行时候程序会异常退出。
39  3.类方法不依赖于对象,所以其不能访问成员变量。
40  Tips:对象方法与类方法能同名存在。
41  */
posted on 2015-04-29 23:55 swp 阅读(101) 评论(0)  编辑 收藏 引用 所属分类: objective-c

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理