Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store CGRect values in NSMutableArray?

How would I store CGRect objects in a NSMutableArray, and then later retrieve them?

like image 906
Krishna Chaitanya Bandaru Avatar asked May 29 '10 07:05

Krishna Chaitanya Bandaru


2 Answers

You need to wrap the CG structures in NSValue classes. So:

NSMutableArray* array = [NSMutableArray mutableArray]; [array addObject:[NSValue valueWithCGRect:CGRectMake(0,0,10,10)]]; CGRect someRect = [[array objectAtIndex:0] CGRectValue]; 
like image 110
Jason Coco Avatar answered Sep 18 '22 20:09

Jason Coco


CGRect rect = CGRectMake( 5, 5, 40, 30 ); NSString* rectAsString = NSStringFromCGRect( rect ); CGRect original = CGRectFromString( rectAsString ); 
like image 29
Jane Avatar answered Sep 19 '22 20:09

Jane