开发者

Objective-C: Where to define macros to be available everywhere?

I have an iOS application which uses in many view controllers, the same strings, numbers, etc. So I think it would be much better to define these constants in one file and use it in all the view controller implementations. The advantage will be changing one number, I have to do it only once and not in all view controllers this number is used.

Actually, I have in my .h file such macros:

#de开发者_运维知识库fine aNumber 34.0

and then I can use it in the corresponding .m file. But what's the best way to do this in the whole application? Creating a plain .h file which consists only of such macros and then importing this file in the .h files of the view controllers?

Best Regards, Tim.


The simple way is take constant.h and write all macro there.we have .pch class and import the constant.h into the .pch(pre compile header) file.No need to import constant.h file to each and every viewcontroller.


I think, you are on right way to create a .h files and import that in .m file when needed,

Suggest you to place all the constant in One file and name that myApplicationConstants.h. and import it any number of .m files where the constant is needed.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜