简介

介绍一些CocoaPods一些特别的用法

CocoaPods github地址

CocoaPods 官方地址

编译环境

系统版本:macOS Sierra 10.12.6

Xcode: v9.2(9C40b)

1. 指定第三方库版本

1. 固定版本
  1. target 'MyApp' do
  2. pod 'AFNetworking','3.2.0'
  3. end

这是将AFNetworking 完全限定在 3.2.0版本,不会更新

2.小版本浮动
  1. target 'MyApp' do
  2. pod 'AFNetworking','~> 3.2.0'
  3. end

这样设置 AFNetworking 会在 3.2.0 ~ 3.9.9 之间版本浮动,不包含4.0.0(这里就是泛指,不必较真,不要提AFNetworking 没有3.9.9)

3.完全不限制版本
  1. target 'MyApp' do
  2. pod 'AFNetworking',
  3. end

这样设置 AFNetworking 不限制版本,任何版本都可以,不过下载的版本下来肯定是最新的。

提示

在项目中,我建议使用方法一,也就是固定版本。特别是在多人开发的项目中

在项目中,可能会遇到更新pod。如果不指定版本的花,就会出现每个人第三方库版本不一样

如果是需要更新第三方库,直接修改版本号,更新pod即可。

尽量小组内做到协调统一

4.官方解释版本

  1. '> 0.1' 大于0.1版本
  2. '>= 0.1' 大于等于0.1版本
  3. '< 0.1' 小于0.1版本
  4. '<= 0.1' 小于等于0.1版本
  5. '~> 0.1.2' 大于0.1.2 小于0.2,不含0.2
  6. '~> 0.1' 0.1以上 1.0以下,不含0.1
  7. '~> 0' 0和以上,等于没有此约束

CocoaPods 支持私有Spec仓库,我们可以建立自己的源,也可以使用非官方的源,只要符合规定的都可以指定

  1. source 'https://github.com/CocoaPods/Specs.git'
  2. source 'https://github.com/Artsy/Specs.git'
使用git的HEAD指向的分支
  1. target 'MyApp' do
  2. pod 'AFNetworking',:head
  3. end
使用master分支
  1. target 'MyApp' do
  2. pod 'LBXScan',git:'https://github.com/MxABC/LBXScan.git'
  3. end
指定branch
  1. target 'MyApp' do
  2. pod 'Reachability', :git => 'https://github.com/ashfurrow/Reachability.git', :branch => 'frameworks'
  3. end
指定tag
  1. target 'MyApp' do
  2. pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :tag => '3.2.0'
  3. end
指定commit
  1. target 'MyApp' do
  2. pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :commit => 'e976d63'
  3. end
使用子库
  1. target 'MyApp' do
  2. pod 'QueryKit/Attribute'
  3. end
使用多个子库
  1. target 'MyApp' do
  2. pod 'QueryKit', :subspecs => ['Attribute', 'QuerySet']
  3. end
使用本地库

通过:path 可以指定本地代码,不过需要确保目录中包含 podspec 文件。

  1. target 'MyApp' do
  2. pod 'AFNetworking', :path => '~/Documents/AFNetworking'
  3. end
指定target的依赖库
  1. target 'MyApp' do
  2. pod 'SDWebImage', '4.0'
  3. target 'otherTaget' do
  4. use_frameworks!
  5. pod 'AFNetworking','3.2.0'
  6. end
  7. end
排除target
  1. target 'MyApp' :exclusive => true do
  2. pod 'AFNetworking','3.2.0'
  3. end
指定xocdeproj

默认会使用 podfile 文件同级目录下第一个xcodeproj ,但也是可以指定的

  1. xcodeproj 'testProject'
  2. target:test do
  3. pod 'AFNetworking','3.2.0'
  4. xcodeproj 'otherProject'
  5. end
指定连接的target

如果不显式指定连接的target,Pods会默认连接project的第一个target。如果需要,可以使用link_with指定连接一个活多个target

  1. target link_with 'MyApp','otherApp' do
  2. pod 'AFNetworking','3.2.0'
  3. end
指定依赖库的配置文件
  1. pod 'PonyDebugger', :configuration => ['Release']
指定target的配置文件
  1. xcodeproj 'TestProject', 'Mac App Store' => :release, 'Test' => :debug
使用Dynamic Frameworks代替Static Libraries

通过标志use_frameworks!就可知开启这个功能。如果需要使用Swift的库,就必须加上这个标志了。

抑制警告

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

  1. target 'MyApp' do
  2. pod 'AFNetworking','3.2.0',:inhibit_warnings => true
  3. end
全局抑制警告
  1. platform :ios, '8.0'
  2. inhibit_all_warnings!
  3. target 'MyApp' do
  4. pod 'AFNetworking','3.2.0'
  5. end

iOS CocoaPods一些特别的用法 指定版本、版本介绍、忽略警告的更多相关文章

  1. iOS -- CocoaPods

    CocoaPods 是什么? CocoaPods 是一个负责管理 iOS 项目中第三方开源库的工具.CocoaPods 的项目源码在 GitHub( https://github.com/CocoaP ...

  2. iOS cocoapods升级及问题

    安装 安装RubyCocoaPods基于Ruby语言开发而成,因此安装CocoaPods前需要安装Ruby环境.幸运的是Mac系统默认自带Ruby环境,如果没有请自行查找安装.检测是否安装Ruby:$ ...

  3. iOS.CocoaPods.0

    1. CocoaPods CocoaPods 是Objective-C (iOS and OS X) projects 的依赖管理器. A CocoaPod (singular) is a speci ...

  4. 为ant指定编译版本

    用Eclipse的ant折腾了一天也没搞清楚为什么同样的设置ant出的class版本却不一样.后来下载个ant工具在命令行执行通过. 从网上抄得指定编译版本的方法如下: ant 运行时,必需依赖jdk ...

  5. git 如何让单个文件回退到指定的版本

    1.进入到文件所在文件目录,或者能找到文件的路径查看文件的修改记录 1 $ git log MainActivity.java 结果: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...

  6. linux 安装jdk及tomcat指定jdk版本推荐

    方法1:用yum命令安装 1.   查看当前jdk版本:Java –version,或者是:rpm -qa | grep jdk 2.   删除当前jdk:yum -y remove java-1.6 ...

  7. Eclipse指定JDK版本 Failed to load the JNI shared JVM.dll

    Eclipse指定JDK版本 Failed to load the JNI shared JVM.dll 打开eclipse.ini添加 -vm C:/Java/jdk1.6.0_02/bin 参考: ...

  8. 为tomcat指定JDK版本

    可以为tomcat指定JDK. 当系统中安装有多个版本的jdk时,可以为tomcat指定jdk版本. 在catalina.sh文件和setclasspath.sh文件开头的空白处加上如下一行: exp ...

  9. Buildroot 指定内核版本

    /******************************************************************************** * Buildroot 指定内核版本 ...

随机推荐

  1. 将搜狗词库(.scel格式)转化为txt格式

    参考:http://blog.csdn.net/zhangzhenhu/article/details/7014271 #!/usr/bin/python # -*- coding: utf-8 -* ...

  2. java.sql.SQLException之数组越界

    java.sql.SQLException之数组越界 1.具体错误如下: (1)java.sql.SQLException:Parameter index out of range(0<1) ( ...

  3. (二十五)svn的问题

    今天更新代码到svn中的时候出现了错误,准确的说是在操作更新之前的步骤出现了错误,因此对svn有了更近一步的理解.    check:下载svn中的代码到指定的储存路径中:    update:更新s ...

  4. Array和ArrayList的异同点

    Array和ArrayList的异同点 1.不同点: (1)Array只能存储同构的对象, ArrayList可以存储异构的对象 (2)在CLR托管对中的存放方式中,Array是始终是连续存放的, A ...

  5. Caused by: java.lang.ClassNotFoundException: flex.messaging.io.BeanProxy

    1.错误描述 2014-7-13 1:34:46 org.apache.catalina.startup.HostConfig undeploy 信息: Undeploying context [/b ...

  6. java.sql.SQLException:Invalid value for getInt()-'zhangsan'

    1.错误描述 java.sql.SQLException:Invalid value for getInt()-'zhangsan' 2.错误原因 在遍历打印查询结果时,rs.getInt(3),而在 ...

  7. MySql获取所有表名

    如何获取MySql中所有表的的表名? sql语句是:show tables 返回结果如下: 不仅仅返回了所有的表名,更返回了视图的名字.

  8. Radar Installation POJ - 1328

    Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. ...

  9. tomcat原理(三)结合公司tomcat的用法的在理解

    一,server.xml文件 <?xml version="1.0" encoding="UTF-8"?> <Server port=&quo ...

  10. HttpServletRequest对象

    一.HttpServletRequest介绍 HttpServletRequest对象代表客户端的请求,当客户端通过HTTP协议访问服务器时,HTTP请求头中的所有信息都封装在这个对象中,通过这个对象 ...