iOS - CocoaPods使用总结

1.第三方版本设置

target 'MyApp' do
  //不限制版本,任何版本都可以,默认为最新版本
  pod 'AFNetworking'
  //固定为3.2.0版本,更新也不影响
  pod 'AFNetworking', '3.2.0'
  //大于3.2的版本,不包含3.2
  pod 'AFNetworking', '> 3.2'
  //大于等于3.2的版本,包含3.2
  pod 'AFNetworking', '>= 3.2'
  //小于3.2的版本,不包含3.2
  pod 'AFNetworking', '< 3.2'
  //小于等于3.2的版本,包含3.2
  pod 'AFNetworking', '<= 3.2'
  //大于等于3.2.0,小于3.3,包含3.2.0,不包含3.3
  pod 'AFNetworking', '~> 3.2.0'
  //大于等于3.2,小于4.0,包含3.2,不包含4.0
  pod 'AFNetworking', '~> 3.2'
  //大于等于0,相当于没有约束
  pod 'AFNetworking', '~> 0'
end

提示:
在项目(特别是多人开发的项目)中,建议使用固定版本;
因为每个人的电脑上安装的 CocoaPods 版本可能不一样,所以在更新 pod 时,导致每个人使用第三方版本不同;

2.第三方资源设置

· 使用私有源/官方源

source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/MyPods/Specs.git'

· 使用 git 的 HEAD 指向的分支

target 'MyApp' do
  pod 'AFNetworking',:head
end

· 指定第三方源路径,默认使用 master 分支

target 'MyApp' do
  pod 'AFNetworking',git:'https://github.com/AFNetworking/AFNetworking.git'
end

· 指定源的某个分支

target 'MyApp' do
  pod 'AFNetworking', :git => 'https://github.com/AFNetworking/AFNetworking.git', :branch => 'frameworks'
end

· 指定源的 tag

target 'MyApp' do
  pod 'AFNetworking', :git => 'https://github.com/AFNetworking/AFNetworking.git', :tag => '3.2.0'
end

· 指定源的 commit

target 'MyApp' do
  pod 'AFNetworking', :git => 'https://github.com/AFNetworking/AFNetworking.git', :commit => 'a394932'
end

· 使用子库

target 'MyApp' do
  pod 'AFNetworking/Security'
end

· 使用多个子库

target 'MyApp' do
  pod 'AFNetworking', :subspecs => ['Security', 'Reachability']
end

· 使用本地库

target 'MyApp' do
  //通过 :path 可以指定本地代码,不过需要确保目录中包含 podspec 文件。	
  pod 'AFNetworking', :path => '~/Documents/AFNetworking'
end

· 指定依赖库的配置文件

target 'MyApp' do	
  pod 'AFNetworking', :configuration => ['Release']
end

3. target 设置

· 指定 target 的依赖库

target 'MyApp' do
  pod 'SDWebImage', '4.0'
    target 'otherTaget' do
      use_frameworks!
      pod 'AFNetworking','3.2.0'
    end
end

· 排除 target

target 'MyApp' :exclusive => true do
  pod 'AFNetworking','3.2.0'
end

· 指定连接的 target

target link_with 'MyApp','otherApp' do
  pod 'AFNetworking','3.2.0'
end

· 指定 xocdeproj

//默认会使用 podfile 文件同级目录下第一个 xcodeproj ,但也是可以指定的
xcodeproj 'testProject'
 target:test do
   pod 'AFNetworking','3.2.0'
   xcodeproj 'otherProject'   
end 

· 指定 target 的配置文件

xcodeproj 'TestProject', 'Mac App Store' => :release, 'Test' => :debug

· 使用 Dynamic Frameworks 或 Static Libraries

// Uncomment the next line if you're using Swift 
// or would like to use dynamic frameworks
// use_frameworks!

4.忽略警告

inhibit_warnings 参数能够有效的抑制 CocoaPods 引入的第三方代码库产生的 warning

· 忽略某个第三方的警告

target 'MyApp' do
  pod 'AFNetworking','3.2.0',:inhibit_warnings => true 
end

· 忽略所有第三方警告

platform :ios, '8.0'
 inhibit_all_warnings!
 target 'MyApp' do
   pod 'AFNetworking','3.2.0'
 end
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值