[newbie] Working with NSMutableArrays
[newbie] Working with NSMutableArrays
- Subject: [newbie] Working with NSMutableArrays
- From: Matt Crocker <email@hidden>
- Date: Sat, 15 Nov 2003 20:24:38 +0000
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
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.
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?
Many thanks in advance
matt
_______________________________________________
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.