I'm having trouble with what must be a fairly simple task: adding objects to an NSMutableArray
in Objective-C. Here are the million ways I have tried already:
NSMutableArray* foregroundPoints;
Point point;
// Fails with "No viable conversion from 'Point' to 'id _Nonnull'"
[foregroundPoints addObject: point];
// Fails with "Cannot initialise a parameter of type 'id _Nonull' with an rvalue of type 'Point *'"
[foregroundPoints addObject: &point];
// Fails with: "Illegal type 'Point' used in boxed expression"
[foregroundPoints addObject: @(point)];
Point *pointPtr;
// Fails with "Cannot initialise a parameter of type 'id _Nonull' with an lvalue of type 'Point *'"
[foregroundPoints addObject: pointPtr];
// Fails with "Cannot initialise a parameter of type 'id _Nonull' with an rvalue of type 'Point **'"
[foregroundPoints addObject: &pointPtr];
//Fails with: "Illegal type 'Point *' used in boxed expression"
[foregroundPoints addObject: @(pointPtr)];
What should I be doing to add the Point
to my NSMutableArray
?
(N.B. From the comments and some of the answers I see that I was confused about Point
. I'd assumed it was an Objective-C library class but in fact it was a C++ struct picked up from elsewhere in my project. So my question really boils down to this: how do I add a CGPoint
to an NSMutableArray
? I'll leave the main question unedited as the discussion in the comments and the answers that don't conflate Point
and CGPoint
are also interesting.)