Where to store global constants in an iOS application?

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

    1. I define global constant in YOURPROJECT-Prefix.pch file.
    2. #define BASEURl @"http://myWebService.appspot.com/xyz/xx"
    3. then anywhere in project to use BASEURL:

      NSString *LOGIN_URL= [BASEURl stringByAppendingString:@"/users/login"];
      

    Updated: In Xcode 6 you will not find default .pch file created in your project. So please use PCH File in Xcode 6 to insert .pch file in your project.

    Updates: For SWIFT

    1. Create new Swift file [empty without class] say [AppGlobalMemebers]
    2. & Right away declare / define member

      Example:

      var STATUS_BAR_GREEN : UIColor  = UIColor(red: 106/255.0, green: 161/255.0, blue: 7/255.0, alpha: 1)  //
      
      1. If you want to define the app global member in any class file say Appdelegate or Singleton class or any, declare given member above class definition

提交回复
热议问题