要记 :用字面量语法创建数组和字典的时候 若值为nil会抛出异常 务必保证值中不含nil
NSString *string=@"XXXXXX";
NSNumber *intNumber=@1;
NSNumber *floatNumber=@1.1f;
NSNumber *doubleNumber=@1.211231231;
NSNumber *boolNumber=@YES;
NSNumber *charNumber=@'q';
int x=20;
int y=30;
NSNumber * expressionNumber=@(x*y);
数组字面量
NSArray *animals=[NSArray arrayWithObjects:"dog","cat",nil];
字面量代替的语法
NSArray *animals=@[@"dog",@"cat"];
NSString *dog=animals[1];
字典字面量
NSDictionary *AA=[NSDictionaryWithObjectsAndkeys:@"AA",@"A",@"BB",@"B",[NSNumber numberWithInt:28],@"age",nil];
这个是<对象><健>
NSString *lastName=[ AA objectForKey:@"lastName"];
字面量代替的语法
NSDictionary *AA=@{@"A":@"AA",@"B":@"BB",@"age",@28}; <健><对象>
NSString * lastName=AA[@"lastName"];
可变数组与字典
[mutableArray replaceObjectAtIndex:1 withObject:@"dog"];
[mutableDictionary setObject:@"HSF" forKey:@"lastName"];
字面量代替的语法
mutableArray[1]=@"dog";
mutableDictionary[@"lastName"]=@"HSF";