要記 ?:用字面量語法創(chuàng)建數(shù)組和字典的時候 若值為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);
數(shù)組字面量
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"];
可變數(shù)組與字典
[mutableArray replaceObjectAtIndex:1 withObject:@"dog"];
[mutableDictionary setObject:@"HSF" forKey:@"lastName"];
字面量代替的語法
mutableArray[1]=@"dog";
mutableDictionary[@"lastName"]=@"HSF";