• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: adding objects to mutable dictionary...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >adding objects to mutable dictionary... (From: email@hidden)

  • Prev by Date: Re: NSOutlineView blowing stack
  • Next by Date: Re: styled text to html
  • Previous by thread: Re: adding objects to mutable dictionary...
  • Next by thread: Re: adding objects to mutable dictionary...
  • Index(es):
    • Date
    • Thread