Alex Rivera | Logout

NSNumber constants in Obj-C

Asked 2012-09-04T17:55:45.050
18

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.

Edit
Report

1 Answer

5

You can basically achieve close to what you want in three parts:

.h file:

extern NSNumber *MyFirstConstant;

.m file

NSNumber *MyFirstConstant;

AppDelegate.m

+(void)initialize
{
    MyFirstConstant = @5;
    ...
}

AppDelegate is guaranteed to run before any of your other code, and the initialize is the first method that would be called on AppDelegate, so you can essentially insure all your constants are setup for you before your app runs.

answered 2012-09-04T19:37:52.600

Your Answer