Re: adding objects to mutable dictionary...
Re: adding objects to mutable dictionary...
- Subject: Re: adding objects to mutable dictionary...
- From: Jens Bauer <email@hidden>
- Date: Fri, 20 Feb 2004 02:17:49 +0100
Hi,
On Friday, Feb 20, 2004, at 01:26 Europe/Copenhagen,
email@hidden wrote:
When i cycle through an array and add the objects to a mutable
dictionary the order becoming all jumbled? i would think that they
would stay in the same order but apparently not...
my question is by using setObject wouldn't just add 1after another in
order? but it doesn't seem to be is there some logic to the way it
adds them or not? ie alphabetically or other wise or should i retrieve
them differently?
Uhm, the order is "messed up" because a dictionary uses hashing for a
quicker lookup.
What you'd probably prefer, would be something like:
(pseudo-code/untested)
NSMutableArray *array;
NSMutableDictionary *dict;
while(more data)
{
dict = [NSMutableDictionary dictionary]; // create a new dictionary
for each item in the array.
...
...put some data into the dict using...
[dict setObject:name forKey:@"name"];
[dict setObject:address forKey:@"address"];
[dict setObject:phone forKey:@"phone"];
...
[array addObject:dict];
}
Love,
Jens
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.