- NSMutableArray *array=[[NSMutableArray alloc]initWithObjects:@"apple",@"ab",@"aa",@"aac",@"appd", nil];
- //排序
- [array sortUsingComparator:^NSComparisonResult(__strong id obj1,__strong id obj2){
- NSString *str1=(NSString *)obj1;
- NSString *str2=(NSString *)obj2;
- return [str1 compare:str2];
- }];
- NSLog(@"array=%@",array);
- //枚举字典
- NSNumber *age=[NSNumber numberWithInt:51];
- NSDictionary *dic=[[NSDictionary alloc]initWithObjectsAndKeys:@"Anthony",@"FirstName",@"Robbins",@"LastName",age,@"age", nil];
- [dic enumerateKeysAndObjectsUsingBlock:^(__strong id key,__strong id value,BOOL *stop){
- NSLog(@"Key=%@,Value For Key=%@",key,value);
- }];
- //法二
- NSEnumerator *keys=[dic keyEnumerator];
- id keyInDic=nil;
- while ((keyInDic =[keys nextObject])!=nil) {
- id valueForKey=[dic objectForKey:keyInDic];
- NSLog(@"Key=%@,ValueForKey=%@",keyInDic,valueForKey);
- }
- //NSSet
- NSString *hisName=@"li";
- NSString *hisLastname=@"san";
- NSString *herName=@"zhang";
- NSString *herLastname=@"san";
- NSMutableSet *set=[[NSMutableSet alloc]initWithObjects:hisName,hisLastname,herName,herLastname, nil];
- NSLog(@"%@",set);
- //删除对象
- [set removeObject:herLastname];
- NSLog(@"%@",set);
- //添加
- [set addObject:hisLastname];
- NSLog(@"%@",set);
- [set addObjectsFromArray:array];
- NSLog(@"%@",set);
- //遍历set
- [set enumerateObjectsUsingBlock:^(__strong id objc1,BOOL *stop){
- if ([objc1 isKindOfClass:[NSString class]]) {
- NSString *str=(NSString*)objc1;
- if ([str isEqualToString:@"san1"]) {
- NSLog(@"find san in set");
- *stop=YES;
- }
- }
- }];
- //set anyObject
- NSLog(@"set anyObject:%@",[set anyObject]);//返回一个任意的set值
- NSLog(@"set allObject:%@",[set allObjects]);//遍历所有
转自:http://blog.csdn.net/jidiao/article/details/8138665