Multi-target application scenario
Generally, a project will have test version and production version, and some may have pre-production version, etc. Some parameters of different versions are also different. If it is only managed on a Target, it will be troublesome, and once it is neglected, it will be prone to error. Therefore, in this scenario, multiple targets can solve this problem well. When different targets set different parameters, you only need to package different targets.
How to set multiple targets
1. Create Target, after creating a new project, there will be a default Target, select this Target, right click Duplicate, will generate a XXXX copy Target, and also generate a XXXX copy-info.plist.
xxxx copy
xxxx_production
xxxx copy-Info.plist
xxxx_production_info.plist
Manage schemes
xxxx copy
xxxx_production
1. In the Build Settings of the project, configure Swift Compiler-custom Flags, expand Other Swift Flags, and enter -ddebug on the right of Debug. -d DEBUG can also be used, but no value can be assigned. For example, "-ddebug =1" or "-d DEBUG=1" are invalid. (for Swift)Copy the code
2. In the Build Settings of the project, configure Apple LLVM x. x-preprocessiong and expand Preprocessor Macros. By default, Debug =1 is displayed on the right of Debug. (For Objective-C, C, C++)Copy the code
Tip: in the code editor, the #if branch will have code coloring if the condition is true.Copy the code