Dot-notation in Objective-C's property with struct
937 ワード
Objective-C uses dot-notation for properties, and C uses dot-notation for structs; these can be chained. So, for example, UIView's frame is a property whose value is a struct( a CGRect); thus, you can say myView.frame.size.height, where frame is a property that returns a struct., size is a component of that struct, and height is a component of that struct. But a struct is not a pointer, so you cannot(for example) set a frame's height directly through a chain strarting with the UIView, like this:
Instead, if you want to change a component of a struct property, you must fetch the property value into a struct variable, change the struct variable's value, and set the entire property value from the struct variable:
myView.frame.size.height=23.0; //Compile error
Instead, if you want to change a component of a struct property, you must fetch the property value into a struct variable, change the struct variable's value, and set the entire property value from the struct variable:
CGRect f=myView.frame;
f.size.height=0;
myView.frame=f;