UITouchesのCGPointを配列に格納しようとしています。他のスレッドを読んで、NSValueを使用することがこれを行うための最良の方法であるように思われることに気づきました。現在私は持っています:
NSMutableArray *dotsArray;
NSValue *pointObj;
UITouch *touch = obj;
CGPoint touchPoint = [touch locationInView:self.view];
// Need to store the CGPoints, can't store directly into an array // as it is a C struct // so we use NSValue
// CGPoint converted to NSValue
CGPoint point = touchPoint;
pointObj = [NSValue valueWithCGPoint:point];
dotsArray = [NSArray arrayWithObjects:pointObj,nil];
// Print to console the objects in the collection
NSLog(@"array content: %@", dotsArray);
NSLog(@"[dotsArray count] = %i",[dotsArray count]);
// Restore from NSValue to C structures
CGPoint pointRestored = [pointObj CGPointValue];
使用できるようにしたい:
[dotsArray insertObject:pointObj atIndex:0];
代わりに
dotsArray = [NSArray arrayWithObjects:pointObj,nil];
複数のポイントを保存する方法を思い出しながら、配置を増やすことができるようにします。
読んでみると、これは「insertObject」に必要なIDタイプと関係があると思いますが、完全には理解しておらず、オンラインで解決策を見つけることができません。
編集:私が使用するとき
[dotsArray insertObject:pointObj atIndex:0];
それから
NSLog(@"array content: %@", dotsArray);
NULLを出力します