Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 935115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:06:26+00:00 2026-05-15T21:06:26+00:00

Does Cocoa provide a built-in method to convert a key string into a properly-formatted

  • 0

Does Cocoa provide a built-in method to convert a key string into a properly-formatted set property accessor? i.e. "lineSpacing" -> setLineSpacing:

For example:

NSString * key = @"lineSpacing";
SEL selector = [key magicallyConvertIntoSetPropertyAccessor];

or even:

NSString * key = @"lineSpacing";
SEL selector = NSSelectorFromString([key toSetPropertyAccessor]);

Background:

I’m working on a method that will set a number of properties, by name, using property values stored in a dictionary. I can’t use setObject:forKey because I also use this method for properties that are of built-in types like NSInteger and CGFloat. Here is an example of the method I use for CGFloat, to illustrate:

- (void)setFloatProperty:(NSString *)key value:(CGFloat)value target:(id)object
{
    NSString * setPropertyString = [NSString stringWithFormat:@"set%@",
                                    [key capitalizedString]];
    SEL selector = NSSelectorFromString(setPropertyString);

    NSMethodSignature * signature = ...
    NSInvocation * invocation = ...

    CGFloat arg = value;
    void * argument = &arg;

    [invocation setArgument:argument atIndex:2];
    [invocation invoke];
}

This method works for one-word properties like “color” or “width”, but fails on mulit-word properties like “lineSpacing” or “meaningOfLifeTheUniverseAndEverything” because the capitalize method capitalizes the first letter while setting all subsequent letters to lowercase. Calling the above method using “lineSpacing” as the key results in failure, since the correct property setter would be setLineSpacing: and not setLinespacing:

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:06:26+00:00Added an answer on May 15, 2026 at 9:06 pm

    You’re looking for setValue:forKey:, which not only finds the correct setter selector but sends the message for you. It’s part of the Key-Value Coding protocol; note that getters like myProperty and setters like setMyProperty: are called “Key-Value-Coding-compliant” for this reason.

    I’m working on a method that will set a number of properties, by name, using property values stored in a dictionary.

    See also the setValuesForKeysWithDictionary: method, also part of the KVC protocol.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know of a free tool, similar to what is built into Visual
In a cocoa app of mine, there is a method that does some operations
WINAPI has methods to convert Unicode host names to Punycode. Does Cocoa/Cocoa Touch have
Does anyone know how you can make a cocoa sheet with rounded corners like
Possible Duplicate: How does an underscore in front of a variable in a cocoa
I am Completely new to Objective C and Cocoa programming. Why does NSApplicationMain not
I'm trying to understand how Cocoa does its thing. The Cocoa Template's App Delegate
What Cocoa view does iTunes use to display the library panel?
I have a Cocoa app that does a number of things, but among them,
Somebody told me about a class for language recognition in Cocoa. Does anybody know

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.