Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Problem with Rebel XT (saving as wrong format) Lord Blackadder Digital Photography 4 Jun 22, 2009 01:19 AM
Problems with using my router as an access point showtime Mac OS X Server, Xserve, and Networking 3 Apr 28, 2009 11:13 PM
Problem with UIImageView array and loops orchiss iPhone/iPad Programming 3 Mar 19, 2009 12:33 PM
Problems with File extensions such as .doc and .ppt i4k20c OS X 1 May 7, 2008 07:10 PM
Problems with using the iPod as a Hard Drive King Cobra Mac Help/Tips 53 Aug 5, 2002 10:08 PM

All times are GMT -5. The time now is 09:41 PM.

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

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