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: Gwynne Raskind <email@hidden>
- Date: Sun, 24 May 2009 18:18:12 -0400
On May 24, 2009, at 6:00 PM, Marc Liyanage 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.
My first guess: The class isn't KVC compliant, or more to the point
there's no corresponding -string method. The compiler seems to need
KVC compliance to use property syntax, even though it's not actually
using KVC.
-- Gwynne, Daughter of the Code
"This whole world is an asylum for the incurable."_______________________________________________
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