Xcode及Objective-C新特性
基于Xcode4.4。
- 成员方法无需前置声明
以前我们调用一个未定义的成员方法时,xcode会警告说没有找到该函数。
现在,编译器会先扫描@implementation内的方法,如果存在函数定义,则不出现该警告。
- 自动添加属性
以前我们声明属性@property后,还需要在.m文件中写@synthesize,很麻烦。
现在,我们只需要声明@property name即可,Xcode会自动合成@synthesize name = _name。
- 新增语法特性
通过神奇的@符号,直接简化语法,变身脚本语言!LOL
以前字符串可以这么写:NSString *str = @"Hello";。
现在NSNumber这么写:
NSNumber *number = @1.2;
number = @YES;
数组可以这么写:
NSArray *array = @[@"1", @"2"];
字典可以这么写:
NSDictionary *dict = @{@"key1" : @"value1", @"key2" : @"value2"};
NSString *name = dict[@"name"];