(二)The Podfile

1、什么是 Podfile?

Podfile是描述一个或多个Xcode项目的目标的依赖关系的规范。该文件应该简单地命名为Podfile。


2、举例:

(1)very simple:

target 'MyApp' do
  use_frameworks!
  pod 'Alamofire', '~> 3.0'
end

(2)带官方库 & 私有库地址 & TestBundle:

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

(3)多个 Target 共享相同的 pods :

  • 第 1 种:定义 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
  • 第 2 种:先 define ,后调用:
def common
  pod 'ShowsKit'
  pod 'Fabric'
end

target 'ShowsiOS' do
    common
end

target 'ShowsTV' do
    common
end

3、如何指定 pod 版本?

(1)不指定版本,则在每次 pod install 时,默认安装最新的:

pod 'SSZipArchive'

(2)指定特定的版本号:

pod 'Objection', '0.9'

(3)逻辑运算符指定版本号:

  • '> 0.1' Any version higher than 0.1
  • '>= 0.1' Version 0.1 and any higher version
  • '< 0.1' Any version lower than 0.1
  • '<= 0.1' Version 0.1 and any lower version

(4)~> 运算符指定版本号:

  • '~> 0.1.2' Version 0.1.2 and the versions up to 0.2, not including 0.2 and higher
  • '~> 0.1' Version 0.1 and the versions up to 1.0, not including 1.0 and higher
  • '~> 0' Version 0 and higher, this is basically the same as not having it.

4、如何使用本地文件夹中的文件?

  • 根文件夹下:
pod 'Alamofire', :path => '~/Documents/Alamofire'
  • 与本工程在同一个文件夹下的某一个文件夹文件 & 指定 Git 分支:
pod 'DolphinX',:path => '../DolphinX',:branch => 'develop'

5、From a podspec in the root of a library repo.:

  • master branch:
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git'
  • To use a different branch of the repo:
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'dev'
  • To use a tag of the repo:
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :tag => '3.1.1'
  • Or specify a commit:
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :commit => '0f506b1c45'

你可能感兴趣的:((二)The Podfile)