Where to store global constants in an iOS application?

后端 未结 11 1656
孤城傲影
孤城傲影 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:05

    You could also do a

    #define kBaseURL @"http://192.168.0.123/"
    

    in a "constants" header file, say constants.h. Then do

    #include "constants.h"
    

    at the top of every file where you need this constant.

    This way, you can switch between servers depending on compiler flags, as in:

    #ifdef DEBUG
        #define kBaseURL @"http://192.168.0.123/"
    #else
        #define kBaseURL @"http://myproductionserver.com/"
    #endif
    

提交回复
热议问题