I have a custom object in which I am trying to write a convenience class method that returns an array of CGPoint structures. The reason for this is there are several methods such as CGPathAddLines which take that as a parameter, and a class method would save me from converting my custom objects to an array of CGPoint structures every time. Unfortunately, I am not sure of the best way to achieve this, especially in regards to memory management.
Here is my implementation thus far:
+ (CGPoint*)CGPointsFromData:(NSArray*)data
{
CGPoint *points = (CGPoint*)malloc(data.count * sizeof(CGPoint));
DataPoint *dataPoint;
int i = 0;
for (id object in data) {
if ([object isKindOfClass:[DataPoint class]]) {
dataPoint = (DataPoint*)object;
points[i] = dataPoint.point;
i++;
}
}
return points;
}
Edit: In case it isn't clear, the DataPoint class has a property CGPoint point.
_pointsandpointsas though they are@propertys of an instance, but you are in a class method. Can you show where_points(andpointsfor that matter) are declared/initialized?