CocoaPods为多个target添加依赖库

 

CocoaPods1.0.1依赖库添加方法

自从CocoaPods升级到1.0.1之后,各种坑,之前的link_with语法不能用了,在网上找了好久也没找到解决办法.错误如下:

[!] Invalid `Podfile` file: [!] The specification of `link_with` in the Podfile is now unsupported, please use target blocks instead..

而且我们公司都是快20个target,依赖库都是一样的,Ctrl+c 再 Ctrl+v target 'targetName1' do ... end 这样的语法也是可以解决问题,但是咱们程序员最重要的就是有一颗拒绝复制粘贴的心.
由于Podfile文件是ruby写的,所以我就去网上看了下ruby的语法,写了多个target依赖的库大部分相同的Podfile文件,运行pod install 没问题,全部安装完毕!

编辑工程中的Podfile,根据需求修改库和target名称

多个target公用相同库,还可以添加额外的不同第三方库.

# -*- coding: UTF-8 -*-
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'

# ruby语法
# target数组 如果有新的target直接加入该数组
targetsArray = ['targetName1', 'targetName2', 'targetName3', 'targetName4', 'targetName5']
# 循环
targetsArray.each do |t|
    target t do
        pod 'MJRefresh', '~> 1.4.6'
        pod 'Masonry', '~> 0.6.1'
    end
end

附:
单个target依赖库

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
target 'targetName1' do
    pod 'MJRefresh', '~> 1.4.6'
    pod 'Masonry', '~> 0.6.1'
end

不同target依赖库

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
target 'targetName1' do
    pod 'MJRefresh', '~> 1.4.6'
    pod 'Masonry', '~> 0.6.1'
end

target 'targetName2' do
    pod 'MJRefresh', '~> 1.4.6'
    pod 'Masonry', '~> 0.6.1'
    pod 'AFNetworking', '~> 3.0'
end

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值