#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
//集合
NSDictionary *dic=[[NSDictionary alloc] initWithObjectsAndKeys:@"zs",@"name",@18,@"age",@"lissi",@"name", nil];
NSLog(@"==%lu",[dic count]);
NSLog(@"%@",dic);
NSNumber *age=[dic objectForKey:@"age"];
NSLog(@"----%d",[age intValue]);
NSString *name=[dic objectForKey:@"name"];
NSLog(@"...%@",name);
//***************************************************
NSDictionary *dic3=@{@"name":@"张三",@"age":@18 };
//先写key后写value;*************************************
NSString *name1=dic3 [@"name"];
NSLog(@"---=%@",name1);
//*****************************************************
//字典就是管理多个键值对的集合键(key)通常是NSString的
//值(value)是任意对象。键值对在字典中没有顺序,key不可以重复
//在大量key value结构时。根据key找value的效率高;
NSLog(@"%@",[dic3 allKeys]);
//获取所有的key值。返回数组
NSLog(@"%@",[dic3 allValues]);
//获取所有的value值。返回的也是数组;**************************************************
NSDictionary *dic4=@{@"name":@"张三",@"sex":@"女",@"age":@20};
for(int i=0;i<[dic4 count];i++)
{
NSString *key=[dic4 allKeys][i];
id value=dic4[key];
NSLog(@"key:%@ value:%@",key,value);
}
// 2014-12-09 19:48:21.604 07.字典2[2430:303] key:name value:张三
// 2014-12-09 19:48:21.604 07.字典2[2430:303] key:sex value:女
// 2014-12-09 19:48:21.604 07.字典2[2430:303] key:age value:20
//********************************************************************************
NSMutableDictionary *dic5=[NSMutableDictionary dictionary];
[dic5 setObject:@"zs" forKey:@"name"];
[dic5 setObject:@18 forKey:@"age"];
[dic5 setValue:@"ls" forKey:@"sex"];
//添加,也在一个可变的字典中使用。
[dic5 removeObjectForKey:@"name"];//删一个
[dic5 removeAllObjects];//删完了
//删除,要再一个可变的字典中使用。
NSLog(@"%@",dic5);
//*************************************************
// NSMutableDictionary *dic6=[NSMutableDictionary dictionary];
NSDictionary *area1=@{@"name":@"洛龙",@"number":@100 };
NSDictionary *area2=@{@"name":@"涧西",@"number":@200 };
// NSArray *areas=@[area1,area2];
NSDictionary *city=@{@"name":@"洛阳",@"area3":@[area1, area2]};
NSDictionary *city1=@{@"name":@"郑州",@"area4":@[area1,area2]};
NSDictionary *province=@{@"name":@"河南",@"city":@[city ,city1] };
NSDictionary *country=@{@"name":@"中国",@"province":@[province]};
NSLog(@"%@",country);
//****************************************************
NSMutableArray *array=[@[@120,@80,@69,@99]mutableCopy];
for(int i=0;i <[array count]-1;i++)
{
for(int j=0;j<[array count]-1-i;j++)
{
if([array[j] intValue]>[array[j+1] intValue])
{
[array exchangeObjectAtIndex:j withObjectAtIndex:j+1];
}
}
}
for(NSArray *a in array)
NSLog(@"%@",a );
return 0;
}