views:

78

answers:

2

Hi,

Can someone please help me write the following, without using dot notation:

self.bounds.size.width

I have tried [[[self bounds] size] width], but this results in an error. Any ideas?

+7  A: 

You have brushed up against the ambiguity of dot syntax.

You want:

[self bounds].size.width

-bounds returns an NSRect C structure. Thus, you use traditional dots to access the items within.

bbum
Excellent - thanks a lot. I have tried to avoid dot notation for a long while without knowing exactly why. This has shed some light on the issues it raises. Thanks
Jack
+5  A: 

To avoid mixed notation, I might prefer to use a local temporary C struct variable:

CGRect myBoundsRect = [ self bounds ];
foo = myBoundsRect.size.width;

That way the difference between object messages and C structure member accesses is explicitly separated.

hotpaw2