What is an XCConfig file
Simply put, xcConfig is a configuration file that Apple uses in Xcode files to enable the same set of code to compile and run under different conditions
How to generate and configure a configuration file
- 1. Add a new file to the project, select the configuration file template, and name it
- 2. Configure the newly added file in project configuration
1-n
An environmentxcconfig
file
- 3. Now you can happily develop with a variety of configurations
xcconfig
File Syntax introduction
- Xcconfig has a simple key-value pairing syntax, as follows
BUILD_SETTING_NAME = value
Copy the code
- annotation
Xcconfig supports only one comment \\
-
Use #include to import additional Settings
xcconfig
Files can be created multiple times and can be created inxcconfig
According to the demand, will be otherxcconfig
Import the configuration to this file through#include
The corresponding xcconfig file path on keyword + will do
1. Absolute paths can be added
#include "/Users/someone/testxcConfig/testxcConfig/testxcConfig.Debug.xcconfig"
Copy the code
2. Support relative path, which is actually the file path after ${SRCROOT} path link
#include "testxcConfig/testxcConfig.Debug.xcconfig"
Copy the code
variable
Variable definition, named according to OC, consists of uppercase letters, digits, and underscores only, uppercase in principle, but can also be lowercase; The string can be “or”; There are three special cases of variables:
1. Inxcconfig
Defined variables andBuild Setting
If the variables are the same, then the overwrite situation will occur and can be passed$(inherited)
Keyword inheritanceBuild Setting
, for example:
OTHER_LDFLAGS = -framework SDWebImage OTHER_LDFLAGS = $(inherited) - Framework AFNetworking // OTHER_LDFLAGS = -framework SDWebImage -framework AFNetworkingCopy the code
Note: Some variables cannot be configured to Build Settings through xcConfig. For example, PRODUCT_BUNDLE_IDENTIFIER does not work
2. Reference variablesThe ${}
andRMB ()
Can be
VALUE=OC
LANAUAGE=$(VALUE)-${VALUE}
Copy the code
The conditional variable, according toSDK
.Arch
andConfigration
Condition the Settings
// Set 'Configration' to 'Debug' // Set 'SDK' to 'simulator', 'iphoneOS *' or 'MacOSX *' // Set the valid architecture to 'x86_64' OTHER_LDFLAGS[config=Debug][sdk=iphonesimulator*[arch=x86_64]= $(inherited) -framework "Demo"Copy the code
Note: In Xcode 11.4 and later, you can know default to specify the default value if the variable is null
$(BUILD_SETTING_NAME:default=value)
Copy the code
The priority is from high to low
1. Manually configure Target Build Settings
2. The xcconfig file configured in Target
3. Manually configure roject Build Settings
4. Xcconfig file configured in Project