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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:00:34+00:00 2026-06-10T19:00:34+00:00

I want to make some NSNumber constants via the same style used for NSStrings

  • 0

I want to make some NSNumber constants via the same style used for NSStrings in this topic. That is, I’m creating separate constants.h/.m files and importing them into classes that need to access them.

  • 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-10T19:00:36+00:00Added an answer on June 10, 2026 at 7:00 pm

    The trouble with doing this is that there isn’t such a thing as a compile-time constant NSNumber. Only NSString gets that distinction. NSNumbers are always created dynamically. You can fake it by using a function that runs at your program’s startup to initialize the variables. Your options:

    1. Create a class with a +load method that performs the initialization.

    2. In the file with the constants, include a function with __attribute__((constructor)). So, for example:

      // Constants.m
      
      NSNumber *someGlobalNumber;
      
      __attribute__((constructor))
      static void InitGlobalNumber() {
          someGlobalNumber = [[NSNumber numberWithInteger:1] retain];
      }
      

    But of course then you can’t reliably use these numbers in any other functions which are run that early in the startup process. This usually isn’t a problem, but is worth keeping in mind.

    The other option, which I’ve seen crop up a few times, is to have a class with accessors for the numbers instead of giving raw access to the variables. It’s a bit of a heavier design, but it also feels less voodooish, which has its charms.

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

Sidebar

Related Questions

I want to make some buttons that look like this the following: I've looked
Let's say I want make some of my sources publicly available via my blog
I want to make some custom htaccess rule for some page in magento.for this
I want to make some static constants globally visible. I'm pretty familiar how to
I want to make some change on the video that come from the camera.
I want to make some changes to my web site that requires some URL
I want to make some software that would be great if it do not
I want to make some thing like this my-php-file.php $lang = 'es'; my-js-file.js if
I want to make some re-useable, somewhat-dynamic TSQL code that can be called within
I want to make some functions that are re-usable by any model so that

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.