`
blessdyb
  • 浏览: 231777 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Dot-notation in Objective-C's property with struct

 
阅读更多

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:

 

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;
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics