您好我有字典的以下數組和,我想使用的關鍵「出生日期」的陣列進行排序和我的代碼如下分類詞典
NSLog(@"nodeEventArray == %@", temp);
NSSortDescriptor *dateDescriptor = [NSSortDescriptor
sortDescriptorWithKey:@"BirthDate"
ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:dateDescriptor];
NSArray *sortedEventArray = [temp
sortedArrayUsingDescriptors:sortDescriptors];
NSLog(@"sortedEventArray == %@", sortedEventArray);
,但我無法正確地分類任何一個可以請告訴我如何根據「出生日期」鍵。自誕生之日起字典的數組排序即將作爲字符串從服務
字典的樣本數組:
nodeEventArray = (
{
BirthDate = "05/04/1986";
Email = "";
FirstName = Test;
IsSpouse = 0;
LastName = Test;
MiddleInitial = "";
PatientID = "";
Phone = "";
ScacntronCSVId = 40409;
SlotID = 1;
UserName = "Tes_02192013010055";
},
{
BirthDate = "02/14/1986";
Email = "";
FirstName = Guest;
IsSpouse = 0;
LastName = Guest;
MiddleInitial = "";
PatientID = "";
Phone = "";
ScacntronCSVId = 40410;
SlotID = 2;
UserName = "Gue_02192013014725";
},
{
BirthDate = "02/17/1987";
Email = "";
FirstName = User;
IsSpouse = 0;
LastName = User;
MiddleInitial = "";
PatientID = "";
Phone = "";
ScacntronCSVId = 40411;
SlotID = 3;
UserName = "Use_02192013020726";
}
)
也許這是你在找什麼:[如何排序一個NSMutableArray與自定義對象呢?](http://stackoverflow.com/questions/805547/how-to-sort-an-nsmutablearray-with-定製對象在它) – cacba 2013-02-19 07:50:38
當你說「正確排序」你是什麼意思? 「BirthDate」只是一個字符串,因此它會按字母順序升序排列。 – Fogmeister 2013-02-19 07:50:43
是啊,你爲什麼不使用'NSDate'來持有* BirthDate *? – trojanfoe 2013-02-19 07:53:48