Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 4, 2009, 07:02 PM   #1
drs
macrumors newbie
 
Join Date: Jun 2009
ObjC: Problem with 2d array, NSPoints as NSValues

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.
drs is offline   0 Reply With Quote
Old Jun 4, 2009, 08:52 PM   #2
Catfish_Man
macrumors 68030
 
Catfish_Man's Avatar
 
Join Date: Sep 2001
Location: Portland, OR
Send a message via AIM to Catfish_Man
Code:
if (v = nil) {
should be

Code:
if (v == nil) {
or, my preferred form

Code:
if(!v) {
Catfish_Man is offline   0 Reply With Quote
Old Jun 4, 2009, 09:00 PM   #3
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Dallas, TX
Disregard, I got confused.

-Lee

Last edited by lee1210; Jun 4, 2009 at 09:55 PM.
lee1210 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
call custom objc class from python ruchi830 Mac Programming 1 Jan 14, 2013 09:33 PM
Array Containing Dictionaries ahan.tm iPhone/iPad Programming 2 Nov 18, 2012 11:31 AM
Resolved: Quick question about C++ and ObjC Luigi3 iPhone/iPad Programming 2 Nov 12, 2012 10:50 AM
Modern ObjC compatibility with older iOS? KarlJay iPhone/iPad Programming 4 Jun 24, 2012 10:44 PM

Forum Jump

All times are GMT -5. The time now is 03:57 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC