Re: looking for reference to a dictionary
Re: looking for reference to a dictionary
- Subject: Re: looking for reference to a dictionary
- From: Bill Bumgarner <email@hidden>
- Date: Tue, 21 Oct 2008 09:17:22 -0700
On Oct 21, 2008, at 9:08 AM, Stefan Wolfrum wrote:
Hi all,
I have an array. Each array entry is a dictionary. Each dictionary
has two key/value pairs (all are strings).
Now I get from somewhere else the value (a string) corresponding to
one of the keys. It's exactly the same string, content-wise (not
address-wise).
What I need: a reference/pointer to THAT dictionary inside the array
which contains this string as the value of the key (I know what key
it is).
How would I do that?
My knowledge is: to get an array's entry I just have the
objectAtIndex: method. But then I'd need the index where the
dictionary I'm looking for is. How would I get the index without, of
course, iterating through all the array's entries and looking at
every dictionary and comparing my given value with all the values
inside the dictionaries?
First: is iterating over the array contents really causing a
performance problem? Or is it just algorithmically offensive and
you'd like to make it go away in the name of code aesthetics? Maybe
it doesn't need to be changed at all, but if it does....
Change your model.
Your current model -- your current object graph that consists of an
array of dictionaries -- does not support a lookup pattern that you
need to do.
So, change the model.
If order isn't important, maybe your array should really be a
dictionary.
If order is important, you could use a dictionary to store the items
and an array of keys in item order.
b.bum
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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