2015-09-22 88 views
0

我有這樣的NSMutableArray如何將NSMutableArray的鍵添加到另一個數組中?

2015-09-22 10:12:22.739 amigo[17198:6080591] Headers ************************ (
    { 
    BidAcceptanceRide = 0; 
    BidRejectionRide = 1; 
    BidRide = 1; 
    BookingCancellationByBuyer = 0; 
    BookingCancellationBySeller = 0; 
    BookingConfirmation = 3; 
    BookingRemainder = 0; 
    Review = 0; 
    TotalNotification = 5; 
} 

) 

我想要做的是檢查這些每個鍵值對,如果該值大於0,我想它的鍵添加到另一個陣列。我怎樣才能做到這一點?請幫幫我。

感謝

回答

1

您可以通過以下code嘗試,你可以修改它根據自己的需要。

NSArray * arrHeaders; // Your existing array in which you have value. 
    NSMutableArray * arrSortedData = [NSMutableArray array]; // New array in which you will add data. 


    for (int i = 0; i < [arrHeaders count]; i++){ 

     NSDictionary * dicTeamp = [arrHeaders objectAtIndex:i]; 

     NSMutableDictionary * dicSortedData = [NSMutableDictionary dictionary]; // Dictionary where all keys and value which is greater than 0. 

     for (int j = 0; j < [[dicTeamp allKeys] count]; j++){ 

      if([[dicTeamp valueForKey:[[dicTeamp allKeys] objectAtIndex:j]] intValue] > 0){ 
       [dicSortedData setValue:[dicTeamp valueForKey:[[dicTeamp allKeys] objectAtIndex:j]] forKey:[[dicTeamp allKeys]objectAtIndex:j]]; 
      } 
     } 
     [arrSortedData addObject:dicSortedData]; 
    } 

    NSLog(@"Your sorted data = %@",arrSortedData); 
相關問題