Coding, How-To

iOS: Storing CGRect Items into an NSArray/NSMutableArray

You can store CGRect items into an NSArray. You need to store them as NSValue types:

NSMutableArray framesArray = [[NSMutableArray alloc] init];
CGRect frame = CGRectMake(5, 5, 80, 80);
[framesArray addObject:[NSValue valueWithCGRect:frame]];

Here’s how to retrieve the items later on:


CGRect frame = [((NSValue *)[framesArray objectAtIndex:0]) CGRectValue];

Leave a Reply

Your email address will not be published. Required fields are marked *