(四)Podfile文件(原文翻译)
2017-01-22 18:06
232 查看
学习关于Podfile的一切。Podfile用于在工程中声明依赖。
Podfile文件可以非常简单,这里就是添加Alamofire到一个单独目标的代码:
更复杂的Podfile的例子是链接app和它的测试包:
如果你想要多个目标共享相同的pods,使用抽象目标(abstract_target)。
也可以在Podfile的根节点隐含抽象目标,因此上面的例子可以写成:
之后在这个工程里你可能想要冻结这个Pod的指定版本,在这种情况下你可以指定版本号。
除了不指定版本,或者指定一个版本,也可以使用逻辑运算符:
‘> 0.1’ Any version higher than 0.1 任何比0.1大的版本
‘>= 0.1’ Version 0.1 and any higher version 任何大于等于0.1的版本
‘< 0.1’ Any version lower than 0.1 任何比0.1小的版本
‘<= 0.1’ Version 0.1 and any lower version 任何小于等于0.1的版本
In addition to the logic operators CocoaPods has an optimistic operator ~>:
在逻辑运算符之外,CocoaPods还有乐观运算符~>:
‘~> 0.1.2’ Version 0.1.2 and the versions up to 0.2, not including 0.2 and higher 大于等于0.1.2且小于0.2的版本,不包含0.2及更高版本
‘~> 0.1’ Version 0.1 and the versions up to 1.0, not including 1.0 and higher 大于等于0.1且小于1.0的版本,不包含1.0及更高版本
‘~> 0’ Version 0 and higher, this is basically the same as not having it. 版本0及以上版本,这与不写基本没区别
For more information, regarding versioning policy, see:
关于版本策略的更多信息,请参考:
Semantic Versioning
RubyGems Versioning Policies
There’s a great video from Google about how this works: “CocoaPods and the Case of the Squiggly Arrow (Route 85)”.
使用这个选项时,CocoaPods会假定给出的文件夹是Pod库的根节点,并且直接从那儿连接文件到Pods工程。这意味着你的编辑会在CocoaPods的安装中保持。引用的文件夹可以是从你最喜欢的SCM检出,或者甚至是当前repo(仓库)的git子模块。
注意Pod文件的podspec应该在指定的文件夹里。
要使用repo的主干分支:
要使用repo的不同分支:
要使用repo的tag标签:
或者指定一次提交:
非常重要的提醒是,这意味着这个Pod的版本要满足来自于其他Pods的任何其他依赖。
podspec文件应该在repo的根节点,如果这个库在它的repo中没有podspec文件,你将不得不使用后面章节中介绍的方法之一。
Podfile for a Swift project in Artsy/Eidolon
原文链接:《The Podfile》
1 Podfile是什么?
Podfile是描述一个或多个Xcode工程的目标的依赖的明确说明。这个文件被简单命名为Podfile。本指南中的所有例子都是基于CocoaPods1.0及以前版本的。Podfile文件可以非常简单,这里就是添加Alamofire到一个单独目标的代码:
target 'MyApp' do use_frameworks! pod 'Alamofire', '~> 3.0' end
更复杂的Podfile的例子是链接app和它的测试包:
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
如果你想要多个目标共享相同的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
也可以在Podfile的根节点隐含抽象目标,因此上面的例子可以写成:
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
1.1 从0.x前移到1.0
我们有一个博客帖子深入的解释了这个变化。1.2 指定pod版本
当开始一个工程时,可能你想要使用某个Pod库的最新版本。在这种情况下,简单的删除版本要求即可。pod 'SSZipArchive'
之后在这个工程里你可能想要冻结这个Pod的指定版本,在这种情况下你可以指定版本号。
pod 'Objection', '0.9'
除了不指定版本,或者指定一个版本,也可以使用逻辑运算符:
‘> 0.1’ Any version higher than 0.1 任何比0.1大的版本
‘>= 0.1’ Version 0.1 and any higher version 任何大于等于0.1的版本
‘< 0.1’ Any version lower than 0.1 任何比0.1小的版本
‘<= 0.1’ Version 0.1 and any lower version 任何小于等于0.1的版本
In addition to the logic operators CocoaPods has an optimistic operator ~>:
在逻辑运算符之外,CocoaPods还有乐观运算符~>:
‘~> 0.1.2’ Version 0.1.2 and the versions up to 0.2, not including 0.2 and higher 大于等于0.1.2且小于0.2的版本,不包含0.2及更高版本
‘~> 0.1’ Version 0.1 and the versions up to 1.0, not including 1.0 and higher 大于等于0.1且小于1.0的版本,不包含1.0及更高版本
‘~> 0’ Version 0 and higher, this is basically the same as not having it. 版本0及以上版本,这与不写基本没区别
For more information, regarding versioning policy, see:
关于版本策略的更多信息,请参考:
Semantic Versioning
RubyGems Versioning Policies
There’s a great video from Google about how this works: “CocoaPods and the Case of the Squiggly Arrow (Route 85)”.
2 从本地设备的文件夹路径使用文件
如果你想要联合开发一个Pod库及它的客户端工程,你可以使用:path。pod 'Alamofire', :path => '~/Documents/Alamofire'
使用这个选项时,CocoaPods会假定给出的文件夹是Pod库的根节点,并且直接从那儿连接文件到Pods工程。这意味着你的编辑会在CocoaPods的安装中保持。引用的文件夹可以是从你最喜欢的SCM检出,或者甚至是当前repo(仓库)的git子模块。
注意Pod文件的podspec应该在指定的文件夹里。
2.1 从库repo的根节点里的podspec开始
有时你可能想使用Pod库的最前沿版本、指定的修正版或者你自己的分支。在这种情况下,你可以指定你的pod声明。要使用repo的主干分支:
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git'
要使用repo的不同分支:
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'dev'
要使用repo的tag标签:
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :tag => '3.1.1'
或者指定一次提交:
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :commit => '0f506b1c45'
非常重要的提醒是,这意味着这个Pod的版本要满足来自于其他Pods的任何其他依赖。
podspec文件应该在repo的根节点,如果这个库在它的repo中没有podspec文件,你将不得不使用后面章节中介绍的方法之一。
3 扩展资源
Non-trivial Podfile in Artsy/EigenPodfile for a Swift project in Artsy/Eidolon
原文链接:《The Podfile》
相关文章推荐
- [翻译]运用HtmlInputFile服务器控件上传多个文件
- PhoneGap API帮助文档翻译—File(文件)
- Podfile文件详解
- 第四篇、Swift_Podfile文件配置格式
- cocoapods编辑Podfile文件
- 【翻译】Styling an input type="file"美化文件上传控件
- [原][译][osgearth][EarthFile]关于EarthFile 的Model Layer 讲解(通过earth文件加载模型层)(OE官方文档翻译)
- ios Pod安装使用 + Podfile 文件格式示范
- 多个Target的podfile文件配置
- (二)pod install vs. pod update (原文翻译)
- PhoneGap API帮助文档翻译—File(文件)
- CocoaPod关于Podfile文件编辑时,第三方库版本号的各种写法
- 【翻译自mos文章】在rac中,使用asmcmd命令从 文件系统 move system datafile 到asm磁盘组的方法
- cocoapods 导入SDK时podfile文件内容更新
- 创建Podfile文件,并且加载第三方
- 【翻译自mos文章】对于每一个文件的 file.id and file.incarnation number,重命名文件别名
- 【翻译自mos文章】对于每个文件的 file.id and file.incarnation number,重命名文件别名
- cocoapods 在终端编辑Podfile 文件
- iOS 创建podfile文件以及使用