Reputation: 16302
I have a NSMutableArray
in which I would like to store some CGRect
s:
So, I tried using the following (for example):
UIView *view = [[UIView alloc] initWithFrame:(CGRect){{0, 0}, 50, 50}];
[array1 addObject:[NSValue value:&view->frame withObjCType:@encode(CGRect)]];
But this is causing warning: &view->frame
It is a property, but I would like to access it directly so that I can use the above syntax and use it for the value:
parameter like the above.
I know I could access &self->_view
(if I wanted to add the view to the array, which is not the case here), so I tried &view->frame
(and even &view->_frame
), but it is causing warning and doesn't work.
It would, unless I so the following first:
CGRect tempRect = view.frame;
[array1 addObject:[NSValue value:&tempRect withObjCType:@encode(CGRect)]];
So my question is, what have I done wrong here with &view->frame
(or even: &view->_frame
)?
And is there a way to do that without first having to do this:
CGRect tempRect = view.frame;
[array1 addObject:[NSValue value:&view->frame withObjCType:@encode(CGRect)]];
Other words, can I simply use a cast here without having to create first a CGRect
(tempRect)?
Addendum:
If my memory serves, I think casting on &
in C is invalid. Am not sure, please let me know if my memory is correct.
Upvotes: 1
Views: 228
Reputation: 385870
[array1 addObject:[NSValue valueWithCGRect:view.frame]];
CGRect rect = [[array1 lastObject] CGRectValue];
Documentation: NSValue UIKit Additions Reference
Upvotes: 2