Reputation: 1071
I would like to store the points whenever touchesMoved is called. So far everything is working fine. However what I want to do is to create a "new" array every time touchesMoved is called. For example, once the touch ended the array of points are then saved into database with an identifier of 1. The next time the touchesMoved is called, the array is emptied and replaced with another set of points with a different identifier. I tried incrementing an integer in touchesEnded every time it is called, but I figured out that the integer will remain the same every time the touch ended. So how will I do this? Any help will be very much appreciated.
UPDATE: For example I have this recorded points in my array:
100.000, 200.000
100.000, 202.000
100.000, 204.000
This points will be saved in the database with a identifier, let's say 1.
1 | 100.000 | 200.000
1 | 100.000 | 202.000
1 | 100.000 | 204.000
Now, when the touches moved and ended again, the new set of recorded points will be saved with a different identifier, let's say 2.
2 | 200.000 | 300.000
2 | 200.000 | 302.000
2 | 200.000 | 304.000
So basically what I want to happen is that every time the touchesMoved is called, it will record points that will be saved in an array. When the touches ended, this recorded points will be saved with an identifier. AND, once the touchesMoved is called again and ended, the new set of recorded points will be saved with a different identifier. Any ideas how to do it?
Upvotes: 3
Views: 2759
Reputation: 21221
To store CGPoint
in NSMutableArray
, do this
NSMutableArray *yourCGPointsArray = [[NSMutableArray alloc] init];
[yourCGPointsArray addObject:[NSValue valueWithCGPoint:CGPointMake(100, 100)]];
//Now getting the cgpoint back
CGPoint point = [[yourCGPointsArray objectAtIndex:0] CGPointValue];
Upvotes: 12