NSDictionary *diction = [[NSDictionary alloc] initWithObjectsAndKeys:@"1",@"2",@"3",@"4", nil] ;
NSLog(@"%@", diction);
NSDictionary *dic = @{@"1": @"2",@"3":@"4"};
NSLog(@"%@", dic);
NSLog(@"%ld", diction.count);
NSLog(@"%@", [diction objectForKey:@"2"]);
NSLog(@"%@", diction[@"2"]);
NSLog(@"%@", diction.allKeys);
NSLog(@"%@", [diction allValues]);
NSMutableDictionary *dictionary1 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"1",@"2",@"3",@"4", nil];
for (NSInteger i = 0; i < dictionary1.count; i++) {
NSLog(@"%@ = %@", dictionary1.allKeys[i],dictionary1.allValues[i]);
}
for (NSString *temp in dictionary1) {
NSLog(@"%@ = %@", temp, dictionary1[temp]);
}
[dictionary1 setObject:@"7" forKey:@"8"];
NSLog(@"%@", dictionary1);
[dictionary1 setObject:@"199" forKey:@"8"];
NSLog(@"%@", dictionary1);
[dictionary1 setValue:nil forKey:@"8"];
NSLog(@"%@", dictionary1);
[dictionary1 setValue:@"199" forKey:@"8"];
[dictionary1 removeObjectForKey:@"8"];
NSLog(@"%@", dictionary1);
NSArray *arr1 = @[@"1", @"2", @"3", @"4"];
NSArray *arr2 = @[@"5", @"6", @"7", @"8"];
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:arr1,@"arr1",arr2,@"arr2", nil];
for (NSString *str in dictionary) {
NSArray *arr = dictionary[str];
for (NSString *temp in arr) {
NSLog(@"%@", temp);
}
}
NSDictionary *dic1 = [NSDictionary dictionaryWithObjectsAndKeys:@"杨林",@"name",@"19",@"age", nil];
NSDictionary *dic2 = [NSDictionary dictionaryWithObjectsAndKeys:@"刘山山",@"name",@"20",@"age", nil];
NSDictionary *dic3 = [NSDictionary dictionaryWithObjectsAndKeys:@"商帅",@"name",@"18",@"age", nil];
NSDictionary *dic4 = [NSDictionary dictionaryWithObjectsAndKeys:@"崔磊",@"name",@"21",@"age", nil];
NSArray *array = @[dic1,dic2,dic3,dic4];
for (NSDictionary *dic in array) {
for (NSString *key in dic) {
NSLog(@"%@", dic[key]);
}
}
NSArray *array1 = @[dic1,dic2];
NSArray *array2 = @[dic3,dic4];
NSDictionary *bigDic = [NSDictionary dictionaryWithObjectsAndKeys:array1, @"array1",array2,@"array2", nil];
for (NSString *str in bigDic) {
NSArray *arr = bigDic[str];
for (NSDictionary *dic in arr) {
for (NSString *key in dic) {
NSLog(@"%@", dic[key]);
}
}
}
NSArray *bigArr = @[array1, array2];
for (NSArray *arr in bigArr) {
for (NSDictionary *dic in arr) {
for (NSString *key in dic) {
NSLog(@"%@", dic[key]);
}
}
}
NSMutableDictionary *book1 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"三国演义",@"name",@"100",@"price",nil];
NSMutableDictionary *book2 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"水浒传",@"name",@"200",@"price",nil];
NSMutableDictionary *book3 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"西游记",@"name",@"300",@"price",nil];
NSMutableDictionary *book4 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"红楼梦",@"name",@"400",@"price",nil];
NSMutableDictionary *book5 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"金瓶梅",@"name",@"500",@"price",nil];
NSMutableArray *arr = [NSMutableArray arrayWithObjects:book1,book2,book3,book4,nil];
[arr addObject:book5];
[arr removeObject:book4];
for (NSDictionary *dic in arr) {
if ([dic[@"name"] isEqualToString:@"金瓶梅"]) {
[dic setValue:@"600" forKey:@"price"];
}
}
for (NSMutableDictionary *dic in arr) {
for (NSString *temp in dic) {
NSLog(@"%@ = %@", temp, dic[temp]);
}
}
NSLog(@"**************");
for (NSMutableDictionary *dic in arr) {
for (NSInteger i = 0; i < dic.count; i++) {
NSLog(@"%@ = %@", dic.allKeys[i], dic.allValues[i]);
}
}