我已经设置了一个 NSDictionary 并且我希望它的键作为它的排列。但是当我打印字典日志时,它的 allkeys 和 allkeys 排序它会给我不同的输出。任何方式我都可以获得 NSDictionary 键,因为我已经安排了它。我的代码如下:-
titleDics=[[NSMutableDictionary alloc] init];
[titleDics setObject:@"Exchange" forKey:@"exchange"];
[titleDics setObject:@"Order No" forKey:@"nestordernumber"];
[titleDics setObject:@"Transaction Type" forKey:@"transactiontype"];
[titleDics setObject:@"Symbol Name" forKey:@"symbolname"];
[titleDics setObject:@"Price to fill" forKey:@"pricetofill"];
[titleDics setObject:@"Exchange Order ID" forKey:@"exchangeorderid"];
[titleDics setObject:@"Status" forKey:@"status"];
[titleDics setObject:@"Price Type" forKey:@"pricetype"];
[titleDics setObject:@"Duration" forKey:@"duration"];
[titleDics setObject:@"Product Code" forKey:@"productcode"];
[titleDics setObject:@"Script Name" forKey:@"scripname"];
NSLog(@"Title Dictioanry is %@",titleDics);
NSLog(@"Title dics keys are %@",[titleDics allKeys]);
NSLog(@"Title dics sorted keys are %@",[[titleDics allKeys] sortedArrayUsingSelector:@selector(compare:)]);
输出是:-----
2013-05-30 12:51:43.924 MobileTrading[1676:11303] Title Dictioanry is {
duration = Duration;
exchange = Exchange;
exchangeorderid = "Exchange Order ID";
nestordernumber = "Order No";
pricetofill = "Price to fill";
pricetype = "Price Type";
productcode = "Product Code";
scripname = "Script Name";
status = Status;
symbolname = "Symbol Name";
transactiontype = "Transaction Type";
}
2013-05-30 12:51:43.924 MobileTrading[1676:11303] Title dics keys are (
nestordernumber,
productcode,
symbolname,
pricetype,
exchange,
exchangeorderid,
pricetofill,
scripname,
status,
duration,
transactiontype
)
2013-05-30 12:51:43.924 MobileTrading[1676:11303] Title dics sorted keys are (
duration,
exchange,
exchangeorderid,
nestordernumber,
pricetofill,
pricetype,
productcode,
scripname,
status,
symbolname,
transactiontype
)
我希望这些键按照我设置为 NSDictionary 的顺序,即;
exchange,
nestordernumber,
transactiontype,
symbolname,
pricetofill,
exchangeorderid,
status,
pricetype,
duration,
productcode,
scripname,