指令 | 含义 | 例子 |
@“char” | 指定一个字符串常量 | @“www.baidu.com” |
@"class" c1,c2... | 将c1,c2...声明为类 | @class Person; |
@"defs"(class) | 返回class的结构变量的列表 | struct Class1{@defs(Class2)} |
@encode(type) | 将字符串编码为type类型 | @encode(NSString*) |
@end | 结束类接口部分、类实现部分、协议部分 | @end |
@implementation | 开始一个类的实现部分 | @implementation Class1 |
@interface | 开始一个类的接口部分 | @interface Class1:NSObject |
@private | 定义一个或者多个实例变量的作用域为private | @private {int i;} |
@protected | 定义一个或者多个实例变量的作用域为protected | @protected {int i;} |
@public | 定义一个或者多个实例变量的作用域为public | @public {int i;} |
@property(list)names | 声明属性变量(可以为多个),其中list为可选参数 | @property(retain,nonatomic)NSString *name; |
@protocol | 为指定的protocol创建一个Protocol对象 | @protocol (Copying){...}if([class coformsTo:(protocol)]) |
@procol name | 开始name协议的定义 | @ptocol Copying |
@selector(metch) | method的选择对象 | if([class1 respondsTo:@selector (allocF)]){...} |
@synchronized(object) | 定义一个同步,即在某一个时刻,仅被一个线程占用 | @synchronized(self) |
@synthesize names | 为names生成getter/setter方法(如果开发人员没有提供的话) | @synthesize name; |
@try | 开始捕获异常 | @try{NSString *name;} |
@catch(exception) | 处理捕捉到的异常 | @catch(NSException *e){...} |
@finally | 不管是否抛出异常均会被执行的语句块 | @finally{[name relese];} |
@throw | 抛出一个异常 | @throw e; |