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:
The accepted answer has 2 weaknesses.
First, as others pointed is usage of #define
which is harder to debug, use instead extern NSString* const kBaseUrl
structure.
Second, it defines a single file for constants. IMO, this is wrong because most of classes don't need access to those constants or to access all of them plus file can become bloated if all constants are declared there. A better solution would be to modularize constants at 3 different layers:
System layer: SystemConstants.h
or AppConstants.h
which describes constants at global scope, which can be accessed by any class in the system. Declare here only those constants that must be accessed from different classes that are not related.
Module/Sub-system layer: ModuleNameConstants.h
, describes a set of constants which are typical for a set of related classes, inside of a module/sub-system.
Class layer: Constants resides in the class and are used only by it.
Only 1,2 are related to the question.