Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

drs

macrumors newbie
Original poster
Jun 4, 2009
1
0
HELP!

Using Objective C, I have a 2d array of NSValues holding NSPoints.
At least, that's what I'm TRYING to do.

Creation of 2d array, in init method:
Code:
intersects = [[NSMutableArray arrayWithCapacity:19] retain];
for (int i = 0; i < 19; i++) {
    NSMutableArray *row = [NSMutableArray arrayWithCapacity:19];
    [intersects addObject:row];
}

I did try to use "intersects = [intersects initWithCapacity:19];" but that didn't work. It just didn't seem to register at all.

Then in the method that finds the required points:
I get the 'row' I need to work on: NSMutableArray *row = [intersects objectAtIndex:rNum];
Code:
//Add point to 'row' array from 'intersects' - as NSPoint --> NSValue
NSValue *pt = [NSValue valueWithPoint:NSMakePoint(w, h+y)];
[row addObject:pt];
/*Also tried [row addObject:[pt copy]; Didn't seem to work either.*/
NSLog(@"(%i, %i)", w, h+y);
NSLog(@"%@", pt);
^ The NSLogs print out the right thing. eg:
Code:
(24, 24)
NSPoint: {24, 24}

Then I have a method which goes through the array and prints all the values - or at least, is supposed to:
Code:
- (void) printPoints
{
    NSEnumerator *a = [intersects objectEnumerator];
    NSMutableArray *row;
    NSEnumerator *b;
    NSValue *v;
    while (row = [a nextObject]) {
         b = [row objectEnumerator];
         while (v = [b nextObject]) {
                 if (v = nil) {
                         NSLog(@"Null");
                 }else {
                         NSLog(@"%@", v);
                 }
         }
    }
}
Which gives me this:
(null)
(null)
(null)
...etc

So, where am I going wrong?

Please help me. This is the (fingers crossed) last stumbling block before I'm on the home stretch with this project.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.