(二)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'
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,866评论 0 10
  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 9,921评论 0 13
  • The Inner Game of Tennis W Timothy Gallwey Jonathan Cape ...
    网事_79a3阅读 12,949评论 3 20
  • 成品实现方式 v0.0.1规划 需要考虑到 页面灵活性 + 二次开发 + 引入定制组件 组件的规划 注: 考虑到页...
    郝小淞阅读 1,304评论 0 6
  • 外面的雨声变大了,听起来很着急的样子,哗哗哗的声音闹得失眠了的人更没了睡意。辗转反侧,侧着耳朵,不管是睁着眼...
    耿介先生阅读 282评论 0 0

友情链接更多精彩内容