Where to store global constants in an iOS application?

后端 未结 11 1659
孤城傲影
孤城傲影 2020-11-28 18:01

Most of the models in my iOS app query a web server. I would like to have a configuration file storing the base URL of the server. It will look something like this:

11条回答
  •  温柔的废话
    2020-11-28 18:10

    I do think that another way to do this is far simpler and you will just include it in files you need them included in, not ALL the files, like with the .pch prefix file:

    #ifndef Constants_h
    #define Constants_h
    
    //Some constants
    static int const ZERO = 0;
    static int const ONE = 1;
    static int const TWO = 2;
    
    #endif /* Constants_h */
    

    After that you include this header file in the header file that you want. You include it in header file for the specific class that you want it included in:

    #include "Constants.h"
    

提交回复
热议问题