The basic concept
- Project: contains all the code, resource files, and information of the Project.
- Target: The specific build of the specified code and resource files.
- Scheme: Configures the environment for the specified Target.
Configure multiple environments in different ways
Configure this parameter in Duplicate Target mode
- This generates an additional target and an additional info.plist
- You can define a macro way to do some differential configuration of the code
- Oc in
build setting
->Preprocessor Macros
- Swift in
build setting
->Other Swift Flags
, it should be noted thatswift
To use macros, add-D
parameter - This configuration has disadvantages
- Generate multiple Info.plists
- There are many points that need to be configured
Through Scheme configuration
- through
Edit Scheme
->Manage Schemes
Added schemes for different environments - Again will be different
Scheme
Corresponds to different delta thetaBuild Configuration
mode
Application Scenario Example
- In daily development, in different environments
host url
Addresses will vary by way of defining a macro
- through
info.plist
Files come to light
- Use as follows
NSString *path = [[NSBundle mainBundle] pathForResource:@"Info" ofType:@".plist"];
NSDictionary *infoDict = [[NSDictionary alloc] initWithContentsOfFile:path];
NSLog(@"host url:%@",infoDict[@"HOST_URL"]);
Copy the code
Xcconfig file
Xcconfig guide
- The syntax of the XCConfig file is relatively simple, each configuration file consists of a series of key-value assignments with the following syntax:
BUILD_SETTING_NAME = value
Copy the code
Build Setting
Value Specifies the abbreviation of the field.Build Setting field corresponds to the query
annotation
- The xcconfig file has only one comment method \.
Include Imports other Settings
- As you create the XCConfig file, you can create as many as you need. This means that you can import configuration from other XCConfig using the include keyword. Enclose double quotes after the include keyword:
#include "Debug.xcconfig"
Copy the code
- When searching for imported files, a slash is the absolute path, for example:
#include "/Users/xx/Desktop/... /xxx.xcconfig"Copy the code
- Or through relative paths, starting with the ${SRCROOT} path:
#include "Pods/Target Support Files/xxx.xcconfig"
Copy the code
variable
- Variable definitions, as per OC naming rules, consist only of uppercase letters, digits, and underscores
(_)
Composition, capital in principle, but also not. Strings can be"
It can also be'
Number. - There are three special cases of variables:
-
- in
xcconfig
The variables defined inBuild Settings
Is consistent, then coverage will occur. Can be achieved by$(inherited)
, the current variable inherits the original value of the variable. Such as:
- in
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 via xcConfig. For example, PRODUCT_BUNDLE_IDENTIFIER does not work.Copy the code
-
- Reference variable,
The $()
andThe ${}
Either way you can write it:VALUE=value
- Reference variable,
TEACHER=$(VALUE)-${VALUE} Copy the code
-
- The conditional variable, according to
SDK
,Arch
andConfigration
Conditionalize Settings, for example:
- The conditional variable, according to
// Specify 'Configration' is' Debug '// specify' SDK 'is emulator, // Inherited =x86_64 OTHER_LDFLAGS[config=Debug][SDK =iphonesimulator* -framework "Cat"Copy the code
Note ⚠️ : in Xcode 11.4 and later, you can use default to specify the default value for null variables: $(BUILD_SETTING_NAME:default=value)Copy the code
-
Priority (from highest to lowest) :
-
- Manually configure Target Build Settings
-
- The xcConfig file configured in Target
-
- Manually configure Project Build Settings
-
- The xcConfig file configured in Project