pod引用第三方库的几种方式

时间:2022-11-17 19:47:01

pod引用库的原理,本质上是去找.podspec文件,podspec中包含库的地址及最新的版本号(tag标签),如果pod时没有指定版本,则pod install时会去下载podspec文件中指定的最新版本,如果pod时指定了版本规则,则pod install会按照此版本规则去下载指定的版本

例如想引用YBUtils这个库,有三种方法:

1. 直接从官方的pod repo中引用

pod 'YBUtils' //引用该库的最新版本

pod 'YBUtils', '~>0.1.0' //引用该库的0.1.x版本(x可为>=0的任意值)

这种写法pod install时会默认到本地的pod repo中去找podspec文件,如果找不到的话有两种可能,一种是此第三方库根本不存在,另一种是本地的pod repo没有更新到最新版,需要执行一下pod repo update来更新到最新版

 2. 从指定的git地址中引入

pod 'YBUtils', :git => 'https://github.com/panyibin/YBUtils.git'

pod 'YBUtils', :git => 'https://github.com/panyibin/YBUtils.git', tag=>'0.1.0'

这种写法pod install时会从指定的git地址中去找podspec文件,此例中会去 https://github.com/panyibin/YBUtils.git' 这个地址中去找

 3. 从本地目录中引入

pod 'YBUtils', :path => '../'

这种写法pod install时会从指定的本地目录中去找podspec文件