tags:

views:

137

answers:

2

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

+4  A: 

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];.

Marc Charbonneau
A: 

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]];
Jason Coco

related questions