My cocoa app calculates the location for every mousedown event. The next time the mouse is clicked, the location is overwritten by the new one. How can I store the locations? Is it possible to create an array with mousedown locations?
Thanks
My cocoa app calculates the location for every mousedown event. The next time the mouse is clicked, the location is overwritten by the new one. How can I store the locations? Is it possible to create an array with mousedown locations?
Thanks
Sure you can. Since you're dealing with a primitive struct (NSPoint) you'll need to wrap that in an object before you can put it in an NSArray though. NSValue is a ready-made class that allows you to do this, take a look at [NSValue valueWithPoint:aPoint];
.
It is possible. You could easily do something like this (assume storedLocations
is an ivar of type NSMutableArray
and has been properly initialized):
NSPoint thePoint = [theEvent locationInWindow];
[storedLocations addObject:[NSValue valueWithPoint:thePoint]];