How do I add a CGPoint to NSMutableArray?

前端 未结 6 1781
小蘑菇
小蘑菇 2021-02-01 13:58

I want to store my CGPoint to the NSMutable Array, so , I have method like this:

[self.points addObject:CGPointMake(x, y)];

But I got the error

6条回答
  •  粉色の甜心
    2021-02-01 14:30

    The problem is that CGPoint is actually just a C structure it is not an object:

    struct CGPoint {
       CGFloat x;
       CGFloat y;
    };
    typedef struct CGPoint CGPoint;
    

    If you are on the iPhone you can use the NSValue UIKit additions to convert the CGPoint to an NSValue object.

    See this previous answer for examples: How can I add CGPoint objects to an NSArray the easy way?

提交回复
热议问题