开发者

Application constants used at compilation time

I have many constants 开发者_如何学Goin my application used by many classes of my project. These constants have to be set at compilation time (they are not modified later). For now, I use #define statements at the top of each classe that requires the constant. The problem is that I have to repeat these statement in each classe which requires the constant.

I plan to define all these constants in my main.m or in another .h imported by main.m but I think it is not a good idea.

-> Is there a XCODE / IOS mechanic or file made for that purpose ?

-> If not, is it a good idea to define the constants in my main. ?

Thanks for you help

kheraud


You can write all constants in any .h file , then you can import that file in your projectname_Prefix.pch file .

then you don't need to import file in any other source file . its directly get imported .


you can save them in your *_Prefix.pch then they will apply for all classes without importing another class.


Generally the best way to handle shared constants is to declare them extern in one or more dedicated .h files, and then define them in corresponding implementation files. That way you'll be guaranteed to only have one copy of each constant in your binary, unlike with a #define.


You can provide target-wide compiler defines in Xcode by adding them to the Preprocessor Macros build setting. For example, this might let you create a free Lite version of your application by creating a target for it within your project, then adding a LITE define in the Preprocessor Macros.

See this question for more on this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜