CocoaPods1.0.1依賴庫添加方法
自從CocoaPods升級到1.0.1之后,各種坑,之前的link_with語法不能用了,在網(wǎng)上找了好久也沒找到解決辦法.錯誤如下:
[!] 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 這樣的語法也是可以解決問題,但是咱們程序員最重要的就是有一顆拒絕復(fù)制粘貼的心.
由于Podfile文件是ruby寫的,所以我就去網(wǎng)上看了下ruby的語法,寫了多個target依賴的庫大部分相同的Podfile文件,運(yùn)行pod install 沒問題,全部安裝完畢!
編輯工程中的Podfile,根據(jù)需求修改庫和target名稱
多個target公用相同庫,還可以添加額外的不同第三方庫.
# -*- coding: UTF-8 -*-
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
# ruby語法
# target數(shù)組 如果有新的target直接加入該數(shù)組
targetsArray = ['targetName1', 'targetName2', 'targetName3', 'targetName4', 'targetName5']
# 循環(huán)
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