In iOS development, we may encounter this situation: Some features, some SDK only when debugging, such as using Fbmoryprofiler for memory detection, using the third-party SDK to collect the crash log and so on. Integrating these functions and SDKs into the entire project can result in a bloated project or even a appstore audit. At this time, we can use multiple target, the user does not need the functional part of the target only for development purposes.
First, create multiple target (two ways)
Mode one: Copy a target exactly the same as the current target
Right-click the current target---Duplicate, which will generate a xxx copy of the Target,resource will also generate a XXX copy.plist properties file, this new target and the original target is exactly the same.
Way two: Create a brand new target
1, click on the "+" number below the target list, first will let you choose the target type, since I always refer to the program itself, then the natural Choice application (as for the others, interested in their own research, For example, we can extract parts of the program into a static Library).
2, Next, will let you enter a new target name, rather than the Copy method, the default generation xxxxx copy such as the target name.
3. However, the target generated is almost empty. Copy Bundle Resources, Compile Sources, Link Binary with libraries there is nothing inside. The compilation settings are also in the completely original state.
4. You can complete the target configuration by dragging and dropping the contents to these target settings and adjusting the compilation options.
II. Custom Conditional Compilation macros
When the new target is created, we tend to want to compile the different target differently, then we need to use conditional editing.
1. Add custom conditional compilation macros
Select new target---build setting. Preprocessor Macros found under Apple llvm7.1-preprocessing, double-click to add a custom variable (such as: DEVELOPER)
You can use conditional compilation at this time:
#ifdef DEVELOPER code#endif
Third, add the SDK and source files that need to be used in the new target into the new target.
When you add a third-party framework using Cocoapods, you may have a compile-time link error due to configuration changes, just select None in the configuration, and then restart the pod install
Add multiple target to project