Re: dot notation doesn’t work as expected for some library classes
Re: dot notation doesn’t work as expected for some library classes
- Subject: Re: dot notation doesn’t work as expected for some library classes
- From: Michael Ash <email@hidden>
- Date: Sun, 24 May 2009 18:21:09 -0400
On Sun, May 24, 2009 at 6:00 PM, Marc Liyanage <email@hidden> wrote:
>
> I was playing around a bit with the Obj-C 2.0 dot notation to clarify some
> things for me. In my own classes getters and setters are called as expected,
> but I noticed several times already that library classes sometimes don’t
> allow the dot notation (that’s the reason why I’m trying to clarify this in
> the first place).
>
>
> I’m wondering why this example with NSMutableString does not compile:
>
> #import <Foundation/Foundation.h>
>
> int main (int argc, const char * argv[]) {
> NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
>
> NSMutableString *xyz = [NSMutableString string];
> xyz.string = @"foo";
>
> [pool drain];
> return 0;
> }
>
>
> This fails to build with the message "error: request for member 'string' in
> something not a structure or union". That message is expected when there is
> no such accessor, but it does compile when I replace the dot notation
> accessor with this:
>
> [xyz setString:@"foo"];
>
> This should be exactly the same. I can’t see how this could behave like it
> does when the dot notation is simply syntactic sugar, as the documentation
> states.
It's not exactly the same. The dot syntax only works for *properties*.
As the compiler sees it, a property is either something declared with
@property, a getter, or a getter/setter pair. Since there is no string
getter corresponding to the setString: setter, the compiler does not
see this as a property.
And neither should you. Your use of the dot syntax here is incorrect,
because 'string' is not a property of NSMutableString as the ObjC
language defines (however vaguely) it.
Mike
_______________________________________________
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