nsstring - Does Cocoa provide a built-in method to convert a key into a 'set' property accessor? -


Has Coco provided an inherent method to convert an important string into a properly formatted set property accelerator? I.e. "linespacing" - & gt; SetLineSpacing:

For example:

  NSString * key = @ "lineSpacing"; SEL Selector = [Key Magic ConvertInstantPropertyEser];  

Or even:

  NSString * key = @ "linespacing"; SEL selector = NSSelectorFromString ([key to SerpropertyAccessor]);  

Background:

I am working on a method which, based on the names, Will make a dictionary I can not use the setObject: forKey because I also use this method for the properties that have the underlying type like NSInteger and CGFloat Is. For example, I have an example of how to use CGFloat for example:

  - (zero) setFloatProperty: (NSString *) Key Value: (CGFloat) Value Target: (ID) Object {NSString * SetPropertyString = [NSString stringWithFormat: @ "Set% @", [Key Capitalized String]]; SEL selector = NSSelectorFromString (setPropertyString); NSMethodSignature * signature = ... NSIvvocation * invocation = ... CGFloat arg = value; Zero * argument = & amp; Arg; [Orientation setgrade: index on logic: 2]; [Invoke call]; }  

This method works for one-word properties like "color" or "width", but multi-like "line-spacing" or "meanoff life the universe and everything" -Could fail on keyword properties because the method capitalizes the first letter after setting lowercase all letters. Because the correct property setter setLineSpacing: and setLinespacing:

will not be, because using the above "line spacing" as the main result in the failure Calling method

You are searching for setValue: forKey: , which not only finds the right setter selector But the message sends for you. This is part of; Note that senders such as myProperty and setMyProperty: are called "key-value-coding-compliant" for this reason.

I am working on a method that will set up several properties by using names stored in a dictionary using values ​​of values.

Also see also part of the KVC protocol.


Comments