2012-08-06 75 views
0

我有一個數組有兩個對象,每個對象有31個鍵。我按照字母順序顯示了@「FirstName」。現在我的問題是如何根據@「FirstName」排列其他鍵。我希望數組按名排序。排序NsmutableArray有鍵

下面是我加載到NSMutableArray中的web服務的響應。

(NSMutableArray *) $2 = 0x002afa40 <__NSArrayM 0x2afa40> 
{ 
    AtQRid = "Hiiiiiiiii\n"; 
    City = HKJH; 
    Company = BMBJ; 
    Email = HJKHJKH; 
    EmailStatus = KJHK; 
    EventID = HJBJHGH; 
    FBStatus = KJHK; 
    FirstName = JHGHGJKBN; 
    FollowUPDate = HJHKJ; 
    FollowUPTypeID = KH; 
    ImageURL = VGHV; 
    LastName = MBN; 
    LeadID = H; 
    LinkedinStatus = HKH; 
    Notes = JKHKH; 
    PhoneNo = HJK; 
    Rating = KJNK; 
    ReminderStatus = KJHK; 
    SalesForceStatus = KJHK; 
    State = HJHKH; 
    SurveyQAnswer1 = KJ; 
    SurveyQAnswer2 = HKH; 
    SurveyQAnswer3 = KJ; 
    SurveyQAnswer4 = HK; 
    SurveyQuestion1 = KHK; 
    SurveyQuestion2 = JHK; 
    SurveyQuestion3 = HH; 
    SurveyQuestion4 = KJ; 
    SyncStatus = HKJKH; 
    TwitterStatus = KHJK; 
    UserID = KJBNMN; 
}, 
{ 
    AtQRid = "byeeeeeeeeeeeeeeeeeee\n"; 
    City = hyd; 
    Company = GlobalNest; 
    Email = "[email protected]"; 
    EmailStatus = hahahahah; 
    EventID = 7689; 
    FBStatus = "hey guys"; 
    FirstName = Abhishek; 
    FollowUPDate = 3849934; 
    FollowUPTypeID = kjsndjkvndsk; 
    ImageURL = "www.image.com"; 
    LastName = Naidu; 
    LeadID = 123456789; 
    LinkedinStatus = "good looking "; 
    Notes = "fksd jsdk skdj sdkjks dksjd dmndsn dksndskjkdj gkdjk jdkjdsk sdjksjsdn msd sdnsdnksdjksdjksd sdkn dsmsdnm sd"; 
    PhoneNo = 84377847549; 
    Rating = 5star; 
    ReminderStatus = kjsdjsdf; 
    SalesForceStatus = "i donno"; 
    State = ap; 
    SurveyQAnswer1 = jshdsdjfh; 
    SurveyQAnswer2 = kjshfjkhf; 
    SurveyQAnswer3 = kjsdjsdnn; 
    SurveyQAnswer4 = kjnsjdvnds; 
    SurveyQuestion1 = jsdkfds; 
    SurveyQuestion2 = "kjnsdv,"; 
    SurveyQuestion3 = kjskdvk; 
    SurveyQuestion4 = jskd; 
    SyncStatus = jnsdnmsdm; 
    TwitterStatus = "hey hi"; 
    UserID = 3456; 
} 

回答

3
NSSortDescriptor *descriptor = [NSSortDescriptor 
    sortDescriptorWithKey:@"FirstName" ascending:YES]; 
NSArray *sortedArray = [originalArray sortedArrayUsingDescriptors: 
    [NSArray arrayWithObject:descriptor]];