I'd like to create a property made by an array of CGRect pointers, the number is not defined at the beginning, so I'd like to create a pointer of to a zone o memory that contains the beginning of this array of pointer. It seems quite difficult, I've seen different answer and basing my solution on that.
So far I've writtent that:
@interface ViewController ()
@property (assign) CGRect * rectArray;
@property (strong, nonatomic) NSArray * hotspots;
@end
@implementation ViewController
- (CGRect *) createRectArray {
int count = _hotspots.count;
_rectArray = malloc(sizeof(CGRect*)*count);
for (int i = 0; i<count; i++) {
CGRect currentFrame = ((UIView*)_hotspots[i]).frame;
_rectArray[i] = ¤tFrame;
}
return _rectArray;
}
@end
but the compiler complains telling me that the assignment is not correct.
I'm guessing that probably the correct variable is not a CGRect * rectArray, but a double indirection CGRect ** rectArray.
Is that correct?
[UPDATE]
Actually it doesn't make sense what I want to do... because the property -frame return a copy of CGRect and not a pointer to it, so my idea to have direct and fast access to that is gone.
frameonUIViewis not a piece of memory.UIViewstores onlyboundsandcenter.frameis only a conventient accessor which merges the two properties together.