Re: What are the limitations of Dot Syntax?
Re: What are the limitations of Dot Syntax?
- Subject: Re: What are the limitations of Dot Syntax?
- From: Bill Bumgarner <email@hidden>
- Date: Fri, 05 Dec 2008 16:58:12 -0800
On Dec 5, 2008, at 4:32 PM, Jerry Krinock wrote:
I've been having some unexpected results trying to compile code
using Objective-C's Dot Syntax. I realize that this may be due to
an important question that I didn't find the answer to when I read
about Objective-C 2.0 Properties is: Can you use the dot syntax for
"regular" messages that take 0 arguments?
You can, but don't. The dot syntax is completely orthogonal to
properties, but is definitely intended to be a setter/getter focused
convenience.
To test, I did this:
NSURL* urlIn = [NSURL fileURLWithPath:@"/Hello/World.txt"] ;
NSSet* set = [NSSet setWithObjects:urlIn, nil] ;
And now I want to access those values:
NSString* path ;
NSURL* url ;
And I find that this works:
url = set.anyObject ;
path = url.path ;
So, it looks like the dot syntax is OK with regular messages that
take 0 arguments.
But then, either of these do not compile:
path = set.anyObject.path ;
path = (set.anyObject).path ;
In either case,
error: request for member 'path' in something not a structure or
union
Then why did it work fine when in url.path by itself?
The dot syntax is exactly type precise. As a part of this, the dot
syntax cannot be used to invoke setters/getters on untyped objects --
on object references of type 'id'.
Is this limitation in the Objective-C language, or is it in the
current gcc/Xcode 3.1 version which I am using?
Neither. It is exactly as designed.
Regarding gcc, certainly that error message should be updated to say
"...in something not a structure or union, nor a property".
But, yes, the error message sucks. Feel free to file a bug.
b.bum
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden