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 (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 arch...@mail-archive.com

Reply via email to