14

I have an array, full of CGRects. That part is fine. The problem is when I go to retrieve the CGRects from the array, I'm getting weird errors. Check out my code.

NSArray *frameLocations = [NSArray arrayWithObjects:
                           [NSValue valueWithCGRect:CGRectMake(20, 20, 121, 124)],
                           [NSValue valueWithCGRect:CGRectMake(176, 20, 121, 124)],
                           nil];

Than I get the frame in a for loop, like this:

 CGRect *imageFrame = [[frameLocations objectAtIndex:i] CGRectValue];

I've tried a bunch of different variations, spreading that line out over multiple variables. But I can't seem to get it.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Andrew
  • 3,874
  • 5
  • 39
  • 67

1 Answers1

19

Try:

CGRect imageFrame = [[frameLocations objectAtIndex:i] CGRectValue];

You get an actual CGRect back, not a pointer to a CGRect, because it's a primitive C-style type, not an Objective-C object.

Apart from that your code looks correct.

Tommy
  • 99,986
  • 12
  • 185
  • 204
  • Wow, I feel dumb. Thanks a lot. That really helps me. – Andrew Jul 04 '11 at 18:42
  • 2
    Don't feel dumb — the truth of the matter is that what's a C-style primitive and what's an Objective-C object is often just a pragmatic, performance-related decision. You'll get a feel for which is which over time but there's no inherent difference in naming conventions or anything like that, so it's easy to confuse the two things at first. – Tommy Jul 04 '11 at 18:49
  • 7
    Yeah, they should have called it Subjective-C. – Hot Licks Jul 04 '11 at 19:10