• 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: Dictionary or Array?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Dictionary or Array?


  • Subject: RE: Dictionary or Array?
  • From: "Jonathan E. Jackel" <email@hidden>
  • Date: Fri, 13 Jun 2003 10:24:06 -0400

Lorenzo:

Rethinking how your data model works may help. One option is to use a
setter for your main array that also updates your array of names. Something
like (warning: written in mail):

(void)addDictionaryToDatabase:(NSDictionary *)dict
{
[databaseArray addObject:dict];
[nameArray addObject:[dict objectForKey:name]];
}


You could then re-sort nameArray. It may be more efficient to find the
right place to put the new name and use insertObject:atIndex: instead.

Removing an entry from the database works in reverse:

(void)removeDictionaryFromDatabase:(NSDictionary *)dict
{
[nameArray removeObject:[dict objectForKey:name]];
[databaseArray removeObject:dict];
}

Jonathan

> -----Original Message-----
> From: email@hidden
> [mailto:email@hidden]On Behalf Of Lorenzo
> Sent: Friday, June 13, 2003 8:50 AM
> To: email@hidden
> Subject: Dictionary or Array?
>
>
> Hi list,
> I have a small database I created using a NSMutableArray of
> NSMutableDictionary records.
>
> e.g. If I need to get the field "name" of the record number 2 I do:
>
> name = [[databaseArray objectAtIndex:2] objectForKey:@"name"];
>
> Now I would like to get a pointer to the array containing all the entries
> for the field "name" in order to get the list of all the "names" in my
> database;
>
> Currently I iterate through the databaseArray and get one by one all the
> "name" entries. This requires time. And up above it's not dynamic
> because if
> the user adds a record or modifies a record, I have to rebuild the "names"
> array list.
>
> Is there a way to get "a pointer" to the vertical "names" array?
>
> I thought to rebuild the database using a vertical NSMutableArray for each
> field. Then in order to get a record I should iterate through the fields.
>
> name = [namesArray objectAtIndex:2];
> surname = [surnamesArray objectAtIndex:2];
> ...
>
> Is it a good idea?
>
>
> Best Regards
> --
> Lorenzo
> email: email@hidden
> _______________________________________________
> 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.
_______________________________________________
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: 
 >Dictionary or Array? (From: Lorenzo <email@hidden>)

  • Prev by Date: Re: Some more questions on OCUnit.
  • Next by Date: Re: "-exec ..." in NSTask ?
  • Previous by thread: Re: Dictionary or Array?
  • Next by thread: Re: Dictionary or Array?
  • Index(es):
    • Date
    • Thread