• 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: [newbie] Working with NSMutableArrays
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [newbie] Working with NSMutableArrays


  • Subject: Re: [newbie] Working with NSMutableArrays
  • From: Shawn Erickson <email@hidden>
  • Date: Sat, 15 Nov 2003 12:51:44 -0800

On Nov 15, 2003, at 12:24 PM, Matt Crocker wrote:

Hi folks

I have a piece of code that is reading a series of records from within
a larger file. Each of these records contains a (variable) number of
numeric data entries. What I am trying to do is create a large
NSMutableArray with a number of rows equal to the number of records in
the file. Each of these rows will contain the series of numeric data
entries for that record. This is what I've tried so far:

In myDocument.m I have a section of the file reading code that is
something like:

while (!endFile)
{
...
NSMutableArray *tmpArray = [[NSMutableArray alloc]
initWithCapacity:256] ; //256 is bigger than any of my records

Note NSMutableArray will grow if needed, so try to pick a size that is best at avoiding array growth in common cases but don't worry about it much.

while (!endRecord)
{
...
tmpString = (stuff read from file);
[tmpArray addObject:tmpString];
...
}
NSLog(@"Row size = %i\n",[tmpArray count]);
[docData addObject:tmpArray];
NSLog(@"Whole array size = %i\n",[docData count]);
[tmpArray release];
}

the array docData is defined in myDocument.h as NSMutableArray *docdata;

When I run this code, tmpArray is set up perfectly, and reports "Row
size = 32" (or whatever) at each step. However, I also get "Whole array
size = 0" at each step. Indeed, docData is (null) at the end. I have
tried using the method "addObjectsFromArray" instead, but the result is
the same.

Is docData created someplace? It may be nil and sending messages to nil is basically a no op.

I'm finding this all a bit perplexing as I'm used to FORTRAN and MATLAB
which seem a bit more logical when it comes to data arrays (at least to
me). Can anyone shed any light on my confusion?

You can use standard C arrays in Objective-C if you like.

-Shawn
_______________________________________________
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: 
 >[newbie] Working with NSMutableArrays (From: Matt Crocker <email@hidden>)

  • Prev by Date: Search Hard Drive
  • Next by Date: Re: Search Hard Drive
  • Previous by thread: [newbie] Working with NSMutableArrays
  • Next by thread: Search Hard Drive
  • Index(es):
    • Date
    • Thread