Podfile文件的查看

相关链接


简单说明

CocaPods是用ruby实现的,因此Podfile文件的语法就是ruby的语法。podfile是一个说明文件,用以描述管理一个或者多个Xcode project的rarget的依赖库。这个文件应该且必须被命名为Podfile。

示例一:Podfile链接了app和它的测试bundle:

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

platform :ios, '9.0'
inhibit_all_warnings!

target 'MyApp' do
    pod 'GoogleAnalytics', '~> 3.1'
    # Has its own copy of OCMock 
    # and has access to GoogleAnalytics via the app 
    # that hosts the test target

    target 'MyAppTests' do 
        inherit! :search_paths 
        pod 'OCMock', '~> 2.0.1' 
    end
end

post_install do |installer|
    installer.pods_project.targets.each do |target| 
        puts target.name 
    end
end

示例二:如果你希望多个target共享同一个pods,那么可以用关键字abstract_target:

# There are no targets called "Shows" in any Xcode projects
abstract_target 'Shows' do 
    pod 'ShowsKit' 
    pod 'Fabric'

    # Has its own copy of ShowsKit + ShowWebAuth
    target 'ShowsiOS' do 
        pod 'ShowWebAuth' 
    end

    # Has its own copy of ShowsKit + ShowTVAuth 
    target 'ShowsTV' do 
        pod 'ShowTVAuth' 
    end
end

示例三:

pod 'ShowsKit'
pod 'Fabric'

# Has its own copy of ShowsKit + ShowWebAuth
target 'ShowsiOS' do 
    pod 'ShowWebAuth'
end

# Has its own copy of ShowsKit + ShowTVAuth
target 'ShowsTV' do 
    pod 'ShowTVAuth'
end

指定pod版本


pod 'SSZipArchive'   # 这种情况就是忽略版本需求
pod 'Objection', '0.9'  # 使用特定版本的依赖库

也可以使用逻辑运算符来确认版本

  • ‘> 0.1’ 高于0.1的任何版本
  • ‘>= 0.1’ 版本0.1或更高版本
  • ‘< 0.1’ 低于0.1的任何版本
  • ‘<= 0.1’ 版本0.1或更低的版本

除了逻辑运算符,还有一种运算符:

~ > : 从指定版本到倒数第二位版本号升1为止,比如 ‘~> 1.2.1’是指 1.2.1 <= 版本 < 1.3.0。’~>1.2’是指1.2<= 版本 < 2.0

pod 'AFNetworking'      //不显式指定依赖库版本,表示每次都获取最新版本  
pod 'AFNetworking', '2.0'     //只使用2.0版本  
pod 'AFNetworking', '> 2.0'     //使用高于2.0的版本  
pod 'AFNetworking', '>= 2.0'     //使用大于或等于2.0的版本  
pod 'AFNetworking', '< 2.0'     //使用小于2.0的版本  
pod 'AFNetworking', '<= 2.0'     //使用小于或等于2.0的版本  
pod 'AFNetworking', '~> 0.1.2'     //使用大于等于0.1.2但小于0.2的版本  
pod 'AFNetworking', '~>0.1'     //使用大于等于0.1但小于1.0的版本  
pod 'AFNetworking', '~>0'     //高于0的版本,写这个限制和什么都不写是一个效果,都表示使用最新版本

使用本地文件夹内的依赖库

如果你想建立一个本地依赖库和项目之间的关系,即项目依赖本地文件夹的某个依赖库,可以用关键字path:

pod 'Alamofire', :path => '~/Documents/Alamofire'

使用podspec更新依赖库

使用仓库的master分支:

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

使用仓库中其他分支:

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

使用指定tag的分支:

pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :tag => '3.1.1'

使用指定commit号的版本:

pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :commit => '0f506b1c45'

使用path将把bending文件夹作为pod依赖库的源,并且将会直接从给定的文件夹中把pod依赖库链接进pod项目。这意味着我们队这个本地文件夹的编辑与修改将会被pod直接更新。

名词 解释
source ‘URL’ 指定镜像仓库的源
platform : ios, ‘6.0’ 指定所支持系统和最低版本
inhibit_all_warnings! 屏蔽所有warning
workspace ‘项目空间名’ 指定项目空间名
xcodeproj ‘工程文件名’ 指定xcodeproj工程文件名

CocoaPods pod install/pod update更新慢的问题

默认执行pod install 或者 pod update命令,会更新远程cocopodsde spec库。所以导致命令执行的比较慢,我们可以采用以下命令来提高更新速度,不更新CocoaPods的spec仓库直接install/update。

pod update -verbose -no-repo-update
pod update -verbose -no-repo-update

Podfile和Target

Podfile本质上是用来描述Xcode工程中的targets用的。如果我们不显示指定Podfile对应的target,CocoaPods会创建一个名称为default的隐式target,会和我们工程中的第一个target相对应。换句话说,如果在Podfile中没有指定target,那么只有工程里的第一个target能够使用Podfile中描述的Pods依赖库。

项目存在多个Target情况

项目存在多个Target的时候,需要配置Podfile文件来支持新增加的Target,否则只支持项目默认建立时生成的Target:

a. 多个Target使用相同的pods依赖库

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

# inhibit_all_warnings!
use_frameworks!

abstract_target 'core' do

  pod 'SSZipArchive', :path => '..'

  target 'ObjectiveCExample' do
    platform :ios
  end

  target 'ObjectiveCExampleTests_iOS' do
    platform :ios
  end

  target 'ObjectiveCExampleTests_macOS' do
    platform :osx, '10.8'
  end

  target 'ObjectiveCExampleTests_tvOS' do
    platform :tvos, '9.0'
  end

end

b. 多个的Target需要不同的依赖库

platform :ios  
target :'Test' do  
pod 'Reachability'  
pod 'SBJson'     
pod 'AFNetworking'   
end    

target :'Second' do  
pod 'OpenUDID'   
end

inhibit_all_warnings!的作用,用于屏蔽cocoapods库里面的所有警告。

如果你想屏蔽某pod里面的警告也是可以的:

pod 'SSZipArchive', :inhibit_warnings => true

use_framworks!的作用 : 在pods中用frameworks替代静态库。
另,一般开发swift项目时,我们会在podfile中添加这一句。

podspec文件:后缀名为podspec (cocoapods specification) 的文件是cocoapods的说明文件,该文件为Pods依赖库的描述文件,每个Pods依赖库必须有且仅有那么一个描述文件。该文件包括依赖库的名字、版本、描述、license、author、source、platform等信息。

猜你喜欢

转载自blog.csdn.net/github_33467146/article/details/81092858