匹配我有一个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