iOS - 一个工程多个target引入CocoaPods的方式

一个工程多个target引入CocoaPods的方式

(推荐)方式一:通过abstract方式引入

#targetA: [AFNetworking,Masonry]
#targetB:[AFNetworking,SDWebImage]
abstract_target 'abstract_pod' do  #这里的abstract_pod在实际targets中不存在,是虚拟
    pod 'AFNetworking'
    
    target 'targetA' do
        pod 'Masonry'
    end
    
    target 'targetB' do
        pod 'SDWebImage'
    end
end

方式二:循环target 添加pod

#多个target的pod引入,方式一:如每个pod都引入masonry
targetArray = ['target1','target2']
targetArray.each do |t|
    target t do
        pod 'Masonry', '~> 1.1.0'
    end
end

方式三:提取公共pods 各个target引入

#多个target的pod引入,方式二:如每个pod都引入masonry
def commonPods
    pod 'Masonry', '~> 1.1.0'
end

#工程一:
target 'AnyDoorDemo' do
    commonPods
    pod 'AFNetworking', '~> 3.2.1'
target 'AnyDoorDemoTests' do
    inherit! :search_paths
    pod 'Specta', '~> 1.0.7'
    pod 'OCMock', '~> 3.4.2'
    pod 'Expecta', '~> 1.0.6'
end

  target 'AnyDoorDemoUITests' do
    inherit! :search_paths
    # Pods for testing
  end
end

#工程二:
target 'HostApp' do
    commonPods
end

模板样例

#添加索引库索引文件地址
source 'https://github.com/LGLee/MySpaces.git'
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'

#多个target的pod引入
def commonPods
    pod 'Masonry', '~> 1.1.0'
end

#工程一:
target 'AnyDoorDemo' do
    commonPods
    pod 'AFNetworking', '~> 3.2.1'
    
    #测试相关↓
target 'AnyDoorDemoTests' do
    inherit! :search_paths
    pod 'Specta', '~> 1.0.7'
    pod 'OCMock', '~> 3.4.2'
    pod 'Expecta', '~> 1.0.6'
end

  target 'AnyDoorDemoUITests' do
    inherit! :search_paths
    # Pods for testing
  end
end

#工程二:
target 'HostApp' do
    commonPods
end

结束

你可能感兴趣的:(ios开发)