Multi-environment configuration
Let’s start with three concepts
Project
: contains all the code, resource files, and all the information of the projectTarget
: Specifies how the code and resource files are builtScheme
: Configures the environment for the specified target
In our actual development process, we may need to generate multiple targets for a project in different configurations, so the next step is how to configure multiple environments
Three ways to configure multiple environments
Multiple targets
The specific process is as follows:When wecopy
atarget
And then, thiscopy
thetarget
Will stay with the quiltcopy
thetarget
Same configuration. ChangeLoginApp copy
forLoginApp-Dev
In order to maintain consistency, we need to make corrections in the following areas of the projectIn order to distinguish between the two sets of environments, we need to define macros up front, as you can see in theDebug
Environment, has been defined in advanceDEBUG
We can also add custom macros to this macroThe following isswift
How to add macrosIn the code, you can add new macros to do the control.
The above method is generally cumbersome, generating multiple PList files, and more configuration
The scheme configuration
In this way we add aconfiguration
When we edit scheme, we will find that we have one moreconfiguration
This can be changed during runconfiguration
To configure the environment, or by creating a newscheme
And then we’re going to take this newly createdscheme
theconfiguration
Set toDEV
After going through the above two steps, we adduser-defined value HOST_URL
And stored inplist
In the following code can be passedload plist
File, obtained fromHOST_URL
The value of the
In this way, it is easy to configure multiple environments without generating new targets. This method is relatively simple compared to the first method, but I will still configure some environment variables through build setting
Xconfig file configuration
We can go throughxconfig
File to configure the environmentCreate a new folder,new file -> configuration file
The naming rule starts with the name of the current folder, followed by the name of the app, and then the environment, as shown in the following figurethisxconfig
The file is just storing somekey value
, we created twoxconfig
File will then be selected for the correspondingconfiguration
Under theconfig file
Where the top is rightproject
The following configuration is correcttarget
The configuration of theYou will then enter something in the Config fileAlso configure the plist fileAnd eventually we can get it out in codeplist
In theHOST_URL
The value of PI is equal to PIxconfig
I’m going to set a value in
For example, OTHER_LDFLAGS is an abbreviation of other Link flags in build setting. For details, see the website