OC学习总结(一)
知识要点
1、 类(interface)
》头文件格式.h
@interface class-name : super-class-name <protocol-name,...>{
@private
instance variable
...
@public
...
@protected(default)
...
}
@property ... //点语法中可以方便使用
//xcode4.4以后property关键字实现了三部分工作:成员变量的定义如_name(默认为private),property和synthesize的功能
//构造方法的命名约定(以Person类为例):类方法personWith开头,实例方法initWith开头
//+开头的类方法
//-开头的实例方法
@end
》实现文件.m(.mm)
@implementation class-name
@synthesize ... //点语法中可以方便使用
//实现方法
...
@end
2、 分类(Category)
》头文件格式.h
@interface class-name (category-name)
//+开头的类方法
//-开头的实例方法
@end
》实现文件.m(.mm)
@implementation class-name (category-name)
//实现方法
...
@end
3、 协议(Protocol)
》头文件格式.h
@protocol protocol-name
//协议方法
...
@end