SetiOS tipsgit和pods知识

CocoaPods为多个target添加依赖库

2016-11-25  本文已影响4944人  _时光念你

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

上一篇下一篇

猜你喜欢

热点阅读