Re: How to control the order of enumerating on a NSDictionary
Re: How to control the order of enumerating on a NSDictionary
- Subject: Re: How to control the order of enumerating on a NSDictionary
- From: Graham Cox <email@hidden>
- Date: Mon, 25 Aug 2008 09:43:01 +1000
On 25 Aug 2008, at 9:36 am, JArod Wen wrote:
It should be the problem when enumerating the dictionary, right? How
can I control the order of enumerating?
You can't if you enumerate the keys directly - there is no concept of
"order" for the items of a dictionary. But you can copy them into a
mutable array and sort it as you wish, then enumerate that.
I got the key-value pairs in NSDictionary as following:
"ang (A)" = 2;
"dis (D)" = 1;
"pos (P)" = 0;
"shp (S)" = 3;
Maybe a dictionary isn't the right data structure for the task at
hand? An array might be more appropriate, as it includes the concept
of "order". You appear to be using the dictionary keys to look up an
integer position. Instead, why not just store the column names in an
array where the index is the position?
hth,
Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden