匹配我有一個NSMutable arrray含NSDictionaries這樣的:如何獲得一個數組(說arrayGroupBy)字典從字典中的數組,其中一些關鍵的價值在另一個字典鍵值
<__NSArrayM 0x7a2b4b00>(
{
"appointment_id" = 235;
"component_name" = Anil;
id = 5;
"start_time" = "2014-11-04 19:00:00";
"time_slot" = "7:00 PM";
},
{
"appointment_id" = 235;
"component_name" = "test_book";
id = 19;
"start_time" = "2014-11-04 19:00:00";
"time_slot" = "7:00 PM";
},
{
"appointment_id" = 235;
"component_name" = "New Resource";
id = 21;
"start_time" = "2014-11-04 19:00:00";
"time_slot" = "7:00 PM";
},
{
"appointment_id" = 236;
"component_name" = ctbl;
id = 8;
"start_time" = "2014-11-04 22:00:00";
"time_slot" = "10:00 PM";
},
{
"appointment_id" = 236;
"component_name" = btbl;
id = 7;
"start_time" = "2014-11-04 22:00:00";
"time_slot" = "10:00 PM";
},
{
"appointment_id" = 236;
"component_name" = "New Resource";
id = 21;
"start_time" = "2014-11-04 22:00:00";
"time_slot" = "10:00 PM";
}
)
我如何創建一個新的數組說arrGroupByTimeSlots從上述結構的一些事情是這樣的:
array of time slot
(
time_slot = (an array of dictionaries with matching time_slot)
time_slot = (an array of dictionaries with matching another time_slot)
)
詳細:
(
time_slot = ({
"appointment_id" = 235;
"component_name" = Anil;
id = 5;
"start_time" = "2014-11-04 19:00:00";
"time_slot" = "7:00 PM";
}, {
"appointment_id" = 235;
"component_name" = "test_book";
id = 19;
"start_time" = "2014-11-04 19:00:00";
"time_slot" = "7:00 PM";
}, {
"appointment_id" = 235;
"component_name" = "New Resource";
id = 21;
"start_time" = "2014-11-04 19:00:00";
"time_slot" = "7:00 PM";
}),
time_slot = ({
"appointment_id" = 236;
"component_name" = ctbl;
id = 8;
"start_time" = "2014-11-04 22:00:00";
"time_slot" = "10:00 PM";
}, {
"appointment_id" = 236;
"component_name" = btbl;
id = 7;
"start_time" = "2014-11-04 22:00:00";
"time_slot" = "10:00 PM";
}, {
"appointment_id" = 236;
"component_name" = "New Resource";
id = 21;
"start_time" = "2014-11-04 22:00:00";
"time_slot" = "10:00 PM";
}))
我曾嘗試過:解決方案由提供Onik IV原樣。
更多日誌:關注「time_slot」=「7:00 PM」; 我想字典的數組進行排序:
Printing description of arrAllocated:
<__NSArrayM 0x19055f70>(
{
"appointment_id" = 244;
"component_name" = "badge test";
id = 20;
"start_time" = "2014-11-11 19:00:00";
"time_slot" = "7:00 PM";
},
{
"appointment_id" = 246;
"component_name" = p1;
id = 42;
"start_time" = "2014-11-11 18:00:00";
"time_slot" = "6:00 PM";
},
{
"appointment_id" = 246;
"component_name" = p2;
id = 41;
"start_time" = "2014-11-11 18:00:00";
"time_slot" = "6:00 PM";
},
{
"appointment_id" = 246;
"component_name" = p3;
id = 43;
"start_time" = "2014-11-11 18:00:00";
"time_slot" = "6:00 PM";
},
{
"appointment_id" = 247;
"component_name" = p4;
id = 44;
"start_time" = "2014-11-11 19:00:00";
"time_slot" = "7:00 PM";
},
{
"appointment_id" = 247;
"component_name" = p5;
id = 45;
"start_time" = "2014-11-11 19:00:00";
"time_slot" = "7:00 PM";
},
{
"appointment_id" = 245;
"component_name" = r1;
id = 29;
"start_time" = "2014-11-11 17:00:00";
"time_slot" = "5:00 PM";
},
{
"appointment_id" = 245;
"component_name" = r10;
id = 38;
"start_time" = "2014-11-11 17:00:00";
"time_slot" = "5:00 PM";
},
{
"appointment_id" = 245;
"component_name" = r11;
id = 39;
"start_time" = "2014-11-11 17:00:00";
"time_slot" = "5:00 PM";
},
{
"appointment_id" = 245;
"component_name" = r12;
id = 40;
"start_time" = "2014-11-11 17:00:00";
"time_slot" = "5:00 PM";
},
{
"appointment_id" = 245;
"component_name" = r2;
id = 30;
"start_time" = "2014-11-11 17:00:00";
"time_slot" = "5:00 PM";
},
{
"appointment_id" = 245;
"component_name" = r3;
id = 31;
"start_time" = "2014-11-11 17:00:00";
"time_slot" = "5:00 PM";
},
{
"appointment_id" = 245;
"component_name" = r4;
id = 32;
"start_time" = "2014-11-11 17:00:00";
"time_slot" = "5:00 PM";
},
{
"appointment_id" = 245;
"component_name" = r5;
id = 33;
"start_time" = "2014-11-11 17:00:00";
"time_slot" = "5:00 PM";
},
{
"appointment_id" = 245;
"component_name" = r6;
id = 34;
"start_time" = "2014-11-11 17:00:00";
"time_slot" = "5:00 PM";
},
{
"appointment_id" = 245;
"component_name" = r7;
id = 35;
"start_time" = "2014-11-11 17:00:00";
"time_slot" = "5:00 PM";
},
{
"appointment_id" = 245;
"component_name" = r8;
id = 36;
"start_time" = "2014-11-11 17:00:00";
"time_slot" = "5:00 PM";
},
{
"appointment_id" = 245;
"component_name" = r9;
id = 37;
"start_time" = "2014-11-11 17:00:00";
"time_slot" = "5:00 PM";
}
)
使用Onik IV方法這是我收到講究 「TIME_SLOT」= 「7:00 PM」 排序後;:
<__NSArrayM 0x17e9b660>(
<__NSArrayM 0x19088e80>(
{
"appointment_id" = 244;
"component_name" = "badge test";
id = 20;
"start_time" = "2014-11-11 19:00:00";
"time_slot" = "7:00 PM";
}
)
,
<__NSArrayM 0x190543b0>(
{
"appointment_id" = 246;
"component_name" = p1;
id = 42;
"start_time" = "2014-11-11 18:00:00";
"time_slot" = "6:00 PM";
},
{
"appointment_id" = 246;
"component_name" = p2;
id = 41;
"start_time" = "2014-11-11 18:00:00";
"time_slot" = "6:00 PM";
},
{
"appointment_id" = 246;
"component_name" = p3;
id = 43;
"start_time" = "2014-11-11 18:00:00";
"time_slot" = "6:00 PM";
}
)
,
<__NSArrayM 0x1905d750>
(
{
"appointment_id" = 247;
"component_name" = p4;
id = 44;
"start_time" = "2014-11-11 19:00:00";
"time_slot" = "7:00 PM";
},
{
"appointment_id" = 247;
"component_name" = p5;
id = 45;
"start_time" = "2014-11-11 19:00:00";
"time_slot" = "7:00 PM";
}
)
,
<__NSArrayM 0x190243e0>
(
{
"appointment_id" = 245;
"component_name" = r1;
id = 29;
"start_time" = "2014-11-11 17:00:00";
"time_slot" = "5:00 PM";
},
{
"appointment_id" = 245;
"component_name" = r10;
id = 38;
"start_time" = "2014-11-11 17:00:00";
"time_slot" = "5:00 PM";
},
{
"appointment_id" = 245;
"component_name" = r11;
id = 39;
"start_time" = "2014-11-11 17:00:00";
"time_slot" = "5:00 PM";
},
{
"appointment_id" = 245;
"component_name" = r12;
id = 40;
"start_time" = "2014-11-11 17:00:00";
"time_slot" = "5:00 PM";
},
{
"appointment_id" = 245;
"component_name" = r2;
id = 30;
"start_time" = "2014-11-11 17:00:00";
"time_slot" = "5:00 PM";
},
{
"appointment_id" = 245;
"component_name" = r3;
id = 31;
"start_time" = "2014-11-11 17:00:00";
"time_slot" = "5:00 PM";
},
{
"appointment_id" = 245;
"component_name" = r4;
id = 32;
"start_time" = "2014-11-11 17:00:00";
"time_slot" = "5:00 PM";
},
{
"appointment_id" = 245;
"component_name" = r5;
id = 33;
"start_time" = "2014-11-11 17:00:00";
"time_slot" = "5:00 PM";
},
{
"appointment_id" = 245;
"component_name" = r6;
id = 34;
"start_time" = "2014-11-11 17:00:00";
"time_slot" = "5:00 PM";
},
{
"appointment_id" = 245;
"component_name" = r7;
id = 35;
"start_time" = "2014-11-11 17:00:00";
"time_slot" = "5:00 PM";
},
{
"appointment_id" = 245;
"component_name" = r8;
id = 36;
"start_time" = "2014-11-11 17:00:00";
"time_slot" = "5:00 PM";
},
{
"appointment_id" = 245;
"component_name" = r9;
id = 37;
"start_time" = "2014-11-11 17:00:00";
"time_slot" = "5:00 PM";
} )
)
如果您看到「time_slot」=「7:00 PM」;
它沒有被分組到相同的陣列中,其他「time_slot」=「7:00 PM」;被分組。
希望我能夠使它更清楚。 感謝和問候。
你有什麼嘗試嗎? – 2014-11-04 14:13:46
是的,我已經嘗試過使用謂詞,請參閱編輯 – Alok 2014-11-04 14:16:06
它是否必須是字典?你不能使用自定義對象嗎? – Fogmeister 2014-11-11 10:27:10