large array or text file

Discussion in 'iOS Programming' started by justmyself, Jan 4, 2009.

  1. justmyself macrumors member

    Jan 2, 2009
    I have a large text file of several hundred lines of text and needed to grab a specified line of text. Would I make an array of with each position holding one line of text, or is there a better approach?

    Sorry if this seems so simple but I am new to Objective C and Cocoa. I don't mind taking the time to code the array out, but I have some concerns about the iphone and it's ability to handle an array of such size.

  2. drivefast macrumors regular

    Mar 13, 2008
    your definition of the problem is insufficient. a recommendation depends a lot on whether you need to access one single line, one single time per run, or you would have to access several different lines at different points in time, or on whether the lines in the file are in the order you would access them, and so on. try to offer a few more details.
  3. justmyself thread starter macrumors member

    Jan 2, 2009
    I only need to access one line of text when the application is launched, and at no other time.

    The line number needed would be determined by an int provided by a function. In the array I have coded now is like below

    [textToBeDisplayed setStringValue:array[int]];

    Additionally the text is static and does not be changed/saved etc...

    Hope this helps.
  4. drivefast macrumors regular

    Mar 13, 2008
    then read the lines one by one, counting them, and declare victory when you get to the one you need. internally, reading the file into an array would mean always reading and parsing the whole file, whereas if you read it line by line chances are you need less operations.

Share This Page