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

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


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:
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];
//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:
(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:
- (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) {
                 }else {
                         NSLog(@"%@", v);
Which gives me this:

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, 07:52 PM   #2
macrumors 68030
Catfish_Man's Avatar
Join Date: Sep 2001
Location: Portland, OR
Send a message via AIM to Catfish_Man
if (v = nil) {
should be

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

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


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

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 08:33 PM
Array Containing Dictionaries ahan.tm iPhone/iPad Programming 2 Nov 18, 2012 10:31 AM
Resolved: Quick question about C++ and ObjC Luigi3 iPhone/iPad Programming 2 Nov 12, 2012 09:50 AM
Modern ObjC compatibility with older iOS? KarlJay iPhone/iPad Programming 4 Jun 24, 2012 09:44 PM

Forum Jump

All times are GMT -5. The time now is 03:55 AM.

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

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