Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing CGPoints in NSMutableArray and Sqlite

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?

like image 240
Anna Fortuna Avatar asked Dec 20 '25 11:12

Anna Fortuna


1 Answers

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];
like image 136
Omar Abdelhafith Avatar answered Dec 21 '25 23:12

Omar Abdelhafith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!