I want to store some NSPoints in an array. When I try to use the NSMutableArray:addObject method, the compiler gives me a bad arguement error. Is there a way to add structs to a NSMutableArray, or how else can i acomplish this?
You could create an object with a single field of type NSPoint and add that object to the array. I don't know if this is the most, elegant solution, however. You should try posting your question to a cocoa-dev mailing list.
Seeing your code might help, but I'd guess that you tried to add objects, and not pointers to objects. I think you need to pass pointers to addObject. Example:
// this isn't really good code, but it gets to my point.
<strong>NSPoints are not Objective C objects. Check out NSGeometry.h:
typedef struct _NSPoint {
float x;
float y;
} NSPoint;
typedef NSPoint *NSPointPointer;
typedef NSPoint *NSPointArray;</strong><hr></blockquote>Yes, this is the key. NSArrays can only contain objects. Thus, you'll need to make the point an object with a statement like [NSValue valueWithPoint:thePoint]. NSValues are objects while NSPoints are not. Weird aye?
Comments
-Chris
Edit: spelling
[ 01-27-2003: Message edited by: Josef K. ]</p>
// this isn't really good code, but it gets to my point.
NSPoint mypoint;
NSMutableArray *myArray = [[NSMutableArray alloc] init];
[myArray addObject:&mypoint];
typedef struct _NSPoint {
float x;
float y;
} NSPoint;
typedef NSPoint *NSPointPointer;
typedef NSPoint *NSPointArray;
<strong>NSPoints are not Objective C objects. Check out NSGeometry.h:
typedef struct _NSPoint {
float x;
float y;
} NSPoint;
typedef NSPoint *NSPointPointer;
typedef NSPoint *NSPointArray;</strong><hr></blockquote>Yes, this is the key. NSArrays can only contain objects. Thus, you'll need to make the point an object with a statement like [NSValue valueWithPoint:thePoint]. NSValues are objects while NSPoints are not. Weird aye?