Wednesday, June 11, 2008

An annoyance with properties

I can:

CGFloat x=someLayer.bounds.origin.x;

But I can't:

someLayer.bounds.origin.x=x;

3 Comments:

At 6/12/2008 10:59 AM, Anonymous Anonymous said...

I don't understand why not? (Not questioning your correctness, just hoping for an explanation.)

 
At 6/16/2008 4:45 PM, Anonymous Anonymous said...

Think of the getter of the bounds property as "calculateWhatMyBoundsRectIs". So it makes sense to assign CGFloat x = myView.calculateWhatMyBoundsRectIs.x, but not myView.calculateWhatMyBoundsRectIs.x = 50.0.

The setter is more like "recalculateMySizeBasedOnThisNewBoundsRect". myView.recalculateMySizeBasedOnThisNewBoundsRect = myNewCGRect is ok, but myView.recalculateMySizeBasedOnThisNewBoundsRect.x = 50.0 doesn't jive.

 
At 6/30/2008 11:47 PM, Blogger cjwl said...

This boils down to an incomplete, or inconsistent, implementation in the compiler. Conceptualizing away the underlying problem is easy to do but I think they simply dropped the ball, especially in the context of choosing to use dot syntax for properties.

 

Post a Comment

<< Home