If you want to store the CGPoint to the NSMultable Array  then the following information might be useful.  Suppose you use the

[self.points addObject:CGPointMake(x, y)];  then surly you will get the error like  Incompatible type for argument 1 of “addObject”.

Instead of this one you can use following procedure,

1) Convert the CGPoint into NSValue
CGPoint cgpoint = CGPointMake(100, 100);
NSValue *cgpointObj = [NSValue valueWithCGPoint:cgpoint];

2) Declare the NSMutableArray
NSMutableArray *points = [[NSMutableArray alloc]init]; int arrayCount = 0;
[points insertObject:cgpointObj atIndex:arrayCount++];

3) Restore from NSValue
CGPoint pointRestored = [[points objectAtIndex : 0 ] CGPointValue]

In the same way you can store the CGSize and CGRect values
// CGSize converted to NSValue
CGSize cgsize = CGSizeMake(100, 100);
NSValue *cgsizeObj = [NSValue valueWithCGSize:cgsize];
[points insertObject:cgsizeObj atIndex:arrayCount++];
CGPoint pointRestored = [[points objectAtIndex : 1 ] CGSizeValue];

// CGRect converted to NSValue CGRect cgrect = CGRectMake(100, 100, 50, 50);
NSValue *cgrectObj = [NSValue valueWithCGRect:cgrect];
[points insertObject:cgrectObj atIndex:arrayCount++];
CGPoint pointRestored = [[points objectAtIndex : 2 ] CGRectValue];

Advertisements