Re: Dictionary? Array? or other
Re: Dictionary? Array? or other
- Subject: Re: Dictionary? Array? or other
- From: "Dirk van Oosterbosch, IR labs" <email@hidden>
- Date: Sat, 3 Sep 2005 17:03:41 +0200
On 3-sep-05, at 15:41, Aaron Wallis wrote:
I have a script that collects a large amount of data from a user, each
line entry that the user offers instantiates a object [ a custom class
I developed ] to manage the data, however, Im not to sure what I
should [ or can ] use to bind this data together?
for example, lets just say I have 100 objects that are created via a
loop.
I need each of those 100 objects to have a unique name, and then to be
stored in an array/dictionary/object whatever so I can reference &
call the objects methods at any given time...
...
// Create a expression object to relate to its properties
expressionEntry * tempExpression = [[ expressionEntry alloc ]
init]; <-- this is my custom class
[tempExpression setSeperator : splitStringBy ]; <-- feed
it some variables
[tempExpression setResult : splitStringResult ]; <-- feed
it more variables
// save the object into the array
[ expressionItems setObject: tempExpression
forKey:@"someUniqueID" ]; <-- this is where I would like to save the
objects for later use
This expressionItems should be a dictionary (NSMutableDictionary) if
you want to store the objects under an unique ID, not an array. Use
such unique ID's (and a dictionary to hold them) if you want another
object –besides the collection– to track the objects in the collection.
(e.g. iTunes uses dictionaries and unique ID keys to store songs from
the library in individual playlists).
Use an array (NSArray or NSMutableArray) when you don't need such a
string ordering of objects. If you –or the user– should just be able to
select one or more based on the object's properties (ivars) and work
with the objects from there, an array is much easier. (e.g. when you
would build a calendar with appointments as objects, just store them in
an array and find them by their date as ivar). You also can easily put
up a NSTableView as the UI for an array. It would be slightly more work
with a dictionary.
Also make sure you release the objects (the tempExpression) properly
after you've added them to the array or dictionary, since a collection
retains each object which is added to it. (It increments their retain
count by 1). Or create them with an autorelease.
good luck, d
-----------------------------
Dirk van Oosterbosch
de Wittenstraat 225
1052 AT Amsterdam
the Netherlands
http://labs.ixopusada.com
-----------------------------
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden