@interface some_class : some_parent {
}
@property (nonatomic, assign) CGRect the_rect;
@end
...
@implementation some_class
@synthesize the_rect;
@end
After creating an instance of some_class:
instance_of_some_class.the_rect.origin.x = 0.0;
Which generates an "Expression not assignable" error.
Of course this works fine:
instance_of_some_class.the_rect = CGRectMake(0,0,0,0);
I guess the problem is that the auto-magically created setter only knows about assigning a CGRect to "the_rect". OK, I get that. Can I tell it to not create a setter so that I can access the member variable directly and make assignments to the struct members without having to assign the entire CGRect?
I suppose that I could break this out into four individual CGFloats for origin.x, origin.y, size.width and size.height...but you'd think there would be a way to do this with CGRects instead.
What's confusing is that this, of course, works fine:
CGRect test = instance_of_some_class.the_rect.origin.x;
In other words, the getter knows how to navigate the struct and pull out the value of one of its elements so I can use it. The opposite does not seem to be the case as you just can't reach into an ivar that happens to be a struct and make an assignment to one of its elements without having to assign the entire struct.
I also tried this:
@interface some_class : some_parent {
@public
CGRect the_rect;
}
@property (nonatomic, assign) CGRect the_rect;
@end
After instantiating in another module:
instance.the_rect->origin.x = some_value;
...and got an error saying that the member being referenced is not a pointer. I tried taking the address of instance.the_rect ... but that didn't work either.
EDIT TO CLARIFY: This is about creating a class that has some ivars that happen to be structs. Then, after instantiating the class somewhere else, you want to be able to make assignments to the struct ivar elements directly:
class_instance.struct_ivar.element = something;
I am using CGRect as a convenient example of a well-known struct that one might want to use as an ivar.