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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:49:34+00:00 2026-06-15T21:49:34+00:00

I have a constant defined out of class in SomeClass.h: extern NSString *const SCImportantString;

  • 0

I have a constant defined out of class in SomeClass.h:

extern NSString *const SCImportantString;

@interface SomeClass

@end

And assign it in SomeClass.m:

NSString *const SCImportantString = @"All your base are belong to us.";

@implementation SomeClass

@end

Is there a way to access this extern constant by a string with its name? I know this is possible with class and instant variables using the valueForKey: method.

It would turn very useful to do this while using different build configurations.

  • 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-06-15T21:49:35+00:00Added an answer on June 15, 2026 at 9:49 pm

    If get what you are saying there is no builtin way to get the const pointer value from a string … so there isnt NSConstantFromName(@”xy)

    you could it yourself though

    NSString *const SCConstantByName(NSString *name) {
        if[(name isEqualToString:@"SCImportantString"])
            return SCImportantString;
    }
    

    or for many have a static dict… like the localizables also work:

    NSString *const SCConstantByName(NSString *name) {
        id dict = nil;
        if(!dict) {
            dict = @{@"SCImportantString", SCImportantString};
    
        return dict[name];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a constant in a class, that I defined it by #define HEIGHT
I have a class with a constant defined for it. I then have a
I have several constant defined for a webservice, and I would like to make
I have a Model which has some constants defined, like below: class Order(models.Model): WAITING
I have a question on constant objects. In the following program: class const_check{ int
I have defined a protocol that all my plug-ins must implement. I would also
class SomeClass { //some members MemberClass one_of_the_mem_; } I have a function foo( SomeClass
I have a string constant defined like this: #define kMyString @This is my string
In my little scratch built flex game framework, I have defined a class called
I have defined many constants in GlobalVar.h and other .h files. I import these

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.