У меня есть NSArray, состоящий из других NSArrays. Ниже приведена структура.NSArray в NSMutableDictionary
array (
subArray1 (
type_1_item1,
type_2_item2,
type_3_item3
),
subArray2 (
type_1_item4,
type_2_item5,
type_3_item6
),
subArray3 (
type_1_item7,
type_2_item8,
type_3_item9
)
)
Я хочу изменить структуру, поэтому она представляет собой массив, состоящий из словарей; поэтому структура будет такой.
array (
dictionary1 {
type_1 : item1,
type_2 : item4,
type_3 : item7
},
dictionary2 {
type_1 : item2,
type_2 : item5,
type_3 : item8
},
dictionary3 {
type_1 : item3,
type_2 : item6,
type_3 : item9
}
Это то, что я пробовал до сих пор.
for (int i = 0; i < array.count; i++) {
for (int j = 0; j < [[array objectAtIndex:i] count]; j++) {
NSMutableDictionary *tempDictionary = [[NSMutableDictionary alloc]init];
if (i == 0) {
[tempDictionary setObject:[[array objectAtIndex:i] objectAtIndex:j] forKey:@"type_1"];
}
else if (i == 1) {
[tempDictionary setObject:[[array objectAtIndex:i] objectAtIndex:j] forKey:@"type_2"];
}
else if (i == 2) {
[tempDictionary setObject:[[array objectAtIndex:i] objectAtIndex:j] forKey:@"type_3"];
}
else if (i == 3) {
[tempDictionary setObject:[[array objectAtIndex:i] objectAtIndex:j] forKey:@"type_4"];
}
else if (i == 4) {
[tempDictionary setObject:[[array objectAtIndex:i] objectAtIndex:j] forKey:@"type_5"];
}
else if (i == 5) {
[tempDictionary setObject:[[array objectAtIndex:i] objectAtIndex:j] forKey:@"type_6"];
}
else if (i == 6) {
[tempDictionary setObject:[[array objectAtIndex:i] objectAtIndex:j] forKey:@"type_7"];
}
else if (i == 7) {
[tempDictionary setObject:[[array objectAtIndex:i] objectAtIndex:j] forKey:@"type_8"];
}
else if (i == 8) {
[tempDictionary setObject:[[array objectAtIndex:i] objectAtIndex:j] forKey:@"type_9"];
}
[storage addObject:tempDictionary];
}
}
И это то, что печатает:
{
type_1 = item1;
},
{
type_1 = item4;
},
{
type_1 = item7;
},
{
type_2 = item2;
},
{
type_2 = item5;
},
{
type_2 = item8;
},
{
type_3 = item3;
},
{
type_3 = item6;
}
{
type_3 = item9;
}
)
Вам нужно показать, что вы пробовали, и объяснить, что он делает неправильно. – Wain
Прости, я сделаю это сейчас. – Will
Ваша цель - просто сгенерировать новую структуру с нуля или преобразовать существующий массив в исходную структуру в новую структуру? – rmaddy