Newbie question: keeping track of my objects (Obj-C)

Discussion in 'Mac Programming' started by richyfp, Jul 17, 2007.

  1. richyfp macrumors member

    Apr 13, 2004
    I'm a complete Cocoa newbie and I'm writing a simple program that parses a text file containing multiple DNA sequences. So far, the program parses the file such that the DNA sequences and sequence names are stored in 2 NSMutableArrays (I realise that NSDictionary might be more appropriate with the sequence name as the key, but I haven't got round to that yet).

    So far so good. However, I'm now wanting to have an instance of my new Sequence class to encapsulate the sequence and sequence name so that I can easily query the object for, say, various subsections of the sequence or the sequence length. Does this make sense? If the file contains 10 sequences, I'll have 10 sequence objects with methods like - (int)length and - (NSString)reversecomplement (for retrieving the other DNA strand).

    So, I've made my file parsing code allocate and initialise a sequence object for each sequence it finds in the file. But my question is this: after the objects are initialised, what is the standard way of keeping track of them? Do I use an NSDictionary, an NSArray or is there a standard way of doing this that I'm missing? Basically if I have a sequence object whose sequenceName is Foo, how do I find it again after it's been created?

    I've searched these forums and Google for an answer to this, but with little success... Any help is appreciated!
  2. Eraserhead macrumors G4


    Nov 3, 2005
  3. Nutter macrumors 6502

    Mar 31, 2005
    London, England
    Wow, hang on there! Core Data is a pretty advanced topic.

    Richy, first of all, your approach is absolutely right. Encapsulating each sequence in an object is good design.

    You do need to keep track of the objects you create. The code that parses the file should store the sequence objects in an NSArray, and return that to another part of your code or store it as necessary.

    For example, your app might have a controller object that asks the parser to process a file, and then stores the resulting array of sequence objects in an instance variable. Your user interface and other objects can later query the controller for the array of sequences.
  4. richyfp thread starter macrumors member

    Apr 13, 2004
    Thank you very much! I think the fact that the question is a little more abstract than e.g. "what method do I use for this?" is probably why Googling didn't throw much up...

Share This Page