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 6164215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:57:20+00:00 2026-05-23T21:57:20+00:00

I may be trying to abuse the preprocessor. I want to see if what

  • 0

I may be trying to abuse the preprocessor. I want to see if what I have in mind is even possible.

My class has @properties that all have the same bodies. I want to generate these bodies with a preprocessor macro. E.g.:

- (float) accelerometerSensitivity {
    return [dict floatForSelector:_cmd or:1];
}
- (void) setAccelerometerSensitivity:(float) n {
    [dict setFloat:n forSelector:_cmd];
    [dict writeToFile:[self globalDataFilename] atomically:YES];
}

- (float) returnSpringTension {
    return [dict floatForSelector:_cmd or:0];
}
- (void) setReturnSpringTension:(float) n {
    [dict setFloat:n forSelector:_cmd];
    [dict writeToFile:[self globalDataFilename] atomically:YES];
}
// set*ForSelector methods are in a category on NSMutableDictionary and depend on a function that translates selectors into strings:
// NSString* keyFromSelector(SEL selector);

The idea is that instead of using string literals (or string constants) as keys into the dictionary, I derive the string from the selector name. This way I am sure that the spelling of the key matches the property name and essentially get the benefit of compile-time validation of dictionary keys.

What I want to do is say something like SELECTOR_PROPERY(accelerometerSensitivity) and have it expand into the the getter and the setter. The main difficulty I have in implementing this as a pre-processor macro is generating the setter name from the property name. I need to uppercase the first letter of the property name, and I have no idea how to do that in the preprocessor.

  • 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-23T21:57:22+00:00Added an answer on May 23, 2026 at 9:57 pm

    Nope, you can’t do that.

    But, you can combine identifiers, so in theory you could define this as:

    MACRO(A,a,ccelerometerSensitivity)
    

    It’s somewhat klugey, but it’s more terse than the alternative.

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

Sidebar

Related Questions

I think I may be trying something that isn't possible. I was recently tasked
Sorry this may be blatantly obvious but I have spent all morning trying to
This may be a question that others have seen, but I am trying to
I have been trying to write a script that may help me to comment
I am trying to perform a task that may not be possible. I haven't
I'm trying to find anything that may help with this task: I have a
i'm trying to search terms that may or may not have a space... ex
Im trying to find records in a VARCHAR column that may contain a NUL
I am trying to find out whether local press releases may have affected companies'
I'm trying to parse a log file that looks like this: %%%% 09-May-2009 04:10:29

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.