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?

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?

Is this limitation in the Objective-C language, or is it in the current gcc/Xcode 3.1 version which I am using?

Regarding gcc, certainly that error message should be updated to say "...in something not a structure or union, nor a property".

And Xcode doesn't line up my colons when I paste in a multi-line statement with mix dot syntax and square-brackets mixed. (Please view in monospaced font):

    NSMutableDictionary* dic = [NSMutableDictionary dictionary] ;
    NSSet* set = [NSSet setWithObject:dic] ;
    [set.anyObject setObject:@"parrot"
     forKey:@"bird"] ;
    NSLog([set.anyObject objectForKey:@"bird"]) ;

The above compiles and runs as expected, logging "parrot". But the third and fourth lines are ugly. Xcode should line up the colons like this:

    [set.anyObject setObject:@"parrot"
                      forKey:@"bird"] ;

And, of course, this is definitely an issue with Xcode because it does the same thing even if, instead of set.anyObject, I use foo.bar where 'bar' is declared with @property.

Does anyone know exactly what the rules are here?

Jerry Krinock

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to