Multi-target project is suitable for people who often cannot get through the environment package, and it is convenient to manage projects in different environments. The specific approach can be viewed as a project multi-environment switch, which is suitable for people who often need to play many different environment packages.

How to use pod with multiple targets? Normally, your POD would look like this:

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '8.0'
inhibit_all_warnings!

target 'TestDemo' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!
  # Pods for TestDemo
    pod 'UMessage'
    pod 'MJRefresh'
end

target 'TestDemoBeta' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for TestDemoBeta
    pod 'UMessage'
    pod 'MJRefresh'
end

target 'TestDemoTest' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for TestDemoTest
    pod 'UMessage'
    pod 'MJRefresh'
end

target TestDemoPlatform' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for TestDemoPlatform
    pod 'UMessage'
    pod 'MJRefresh'
end
Copy the code

You can write this if there are fewer third parties, but what if there are more? Here’s an elegant way to write it:

# Uncomment the next line to define a global platform for your project # platform :ios, '9.0' source 'https://github.com/CocoaPods/Specs.git' platform: ios, '8.0' inhibit_all_warnings! def testDemo_pods pod 'UMessage' pod 'MJRefresh' end target 'TestDemo' do # Uncomment the next line if you're using Swift or would like to use dynamic frameworks # use_frameworks! # Pods for TestDemo testDemo_pods end target 'TestDemoBeta' do # Uncomment the next line if you're using Swift or would like to use dynamic frameworks # use_frameworks! # Pods for TestDemoBeta testDemo_pods end target 'TestDemoTest' do # Uncomment the next line if you're using Swift or would like to use dynamic frameworks # use_frameworks! # Pods for TestDemoTest testDemo_pods end target TestDemoPlatform' do # Uncomment the next line if you're using Swift or  would like to use dynamic frameworks # use_frameworks! # Pods for TestDemoPlatform testDemo_pods endCopy the code

You only need to add a definition:

Def testDemo_pods end if pod install is not executed, the name of the definition must not start with an uppercase letterCopy the code

Have you learned? Give it a thumbs up if you like.