// 字典里套数组
NSArray *array1 = @[@"huahau" , @"hehe"];
NSArray *array2 = @[@"xiaobao" , @"liangtao"];
NSDictionary *dic7 = [[NSDictionary alloc] initWithObjectsAndKeys:array1 , @"key1" , array2 , @"key2" , nil];
// NSLog(@"%@" , dic7);
//拿出字典当中的所有key值
NSArray *keyArray3 = [dic7 allKeys];
//外层for循环控制字典有多少 键值对
for (int i = 0; i < [dic7 count]; i++) {
NSArray *a = [dic7 objectForKey:[keyArray3 objectAtIndex:i]];
// 取每一个小数组里面的元素
for (int j = 0; j < [a count]; j++) {
NSLog(@"%@" , [a objectAtIndex:j]);
}
}
NSLog(@"*********************************");
//数组套字典
//创建两个字典
NSDictionary *dic8 = @{@"key1":@"stu1" , @"key2":@"stu2"};
NSDictionary *dic9 = @{@"key3":@"tea1" , @"key4":@"tea4"};
//创建一个数组存放字典
NSArray *dicArray1 = [[NSArray alloc] initWithObjects:dic8 , dic9 , nil];
// NSLog(@"%@" , dicArray1);
//循环控制数组个数得到字典
for (int i = 0; i < [dicArray1 count]; i++) {
NSDictionary *d = [dicArray1 objectAtIndex:i];
//根据键值对取出每个字典元素
NSArray *a1 = [d allKeys];
for (int j = 0; j < [d count]; j++) {
// NSDictionary *dd = [d objectForKey:[a1 objectAtIndex:j]];
// NSLog(@"%@" , dd);
NSLog(@"%@" , [d objectForKey:[a1 objectAtIndex:j]]);
}
}
NSLog(@"***********************************");
//字典套字典
//创建两个小字典
NSDictionary *dic11 = @{@"k1":@"v1" , @"k2":@"v2"};
NSDictionary *dic12 = @{@"k3":@"v3" , @"k4":@"v4"};
//创建大字典
NSDictionary *dic13 = @{@"key5":dic11 , @"key6":dic12};
//根据键值控制小字典
NSArray *dicArray11 = [dic13 allKeys];
for (int i = 0; i < [dic13 count]; i++) {
NSDictionary *dic14 = [dic13 objectForKey:[dicArray11 objectAtIndex:i]];
//根据每个字典键值得到每个字典值
NSArray *dicArray12 = [dic14 allKeys];
for (int j = 0; j < [dic14 count]; j++) {
NSLog(@"%@" , [dic14 objectForKey:[dicArray12 objectAtIndex:j]]);
}
}
NSLog(@"*************************************");
// 数组里面套数组
//创建一个小数组
NSArray *array111 = @[@"aydcuj" , @"dahgh"];
NSArray *array112 = @[@"ujcdjks" , @"hgahd"];
//创建一个大数组
NSArray *bigArray = [NSArray arrayWithObjects:array111 , array112 , nil];
//控制每个数组
for (int i = 0; i < [bigArray count]; i++) {
NSArray *aaa = [bigArray objectAtIndex:i];
//取出每一个小数组元素
for (int j = 0; j < [aaa count]; j++) {
NSLog(@"%@" , [aaa objectAtIndex:j]);
}
}
NSLog(@"************************************");
//创建24个小数组
NSMutableArray *bigArray1 = [NSMutableArray array];
for (int i = 0; i < 24; i++) {
NSMutableArray *miniArray = [NSMutableArray array];
NSNumber *number = [NSNumber numberWithInt:i];
[miniArray addObject:number];
}