On Apr 27, 2009, at 11:09 PM, DairyKnight wrote:

I'm trying to understand how the KVC works in Objective-C. It seems to me that the 'set' method is not case-sensitive? For example, if I define a
class with:

   @interface TestClass : NSObject
   {
        int fido;
        int Fido;
   }

  And have the following set methods:

  -(void) setfido ...
  -(void) setFido ...

Both by calling [self setValue: ... forKey:@"fido"] or [self setValue:... forKey:@"Fido"], the runtime would call the same 'setFido' method. How could
this be?

Because KVC computes the name of the method to invoke by capitalizing the property name. It's not completely insensitive to case, but the first letter will be uppercased.

You should not have two properties which differ only in the case of the first letter of their name. In general, property names should start with a lowercase letter unless the first part of their name is an acronym/initialism, like "URL".

In KVC documentation, you will often see placeholders <key> and <Key> showing how method names are computed from keys. The case in those two placeholders is important. The capitalized placeholder (<Key>) is replaced with the capitalized form of the key name (e.g. "Fido" for the key "fido").

Regards,
Ken

_______________________________________________

Cocoa-dev mailing list ([email protected])

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