Cocoapods Podfile配置
2015-08-01 22:53
453 查看
What is a Podfile?
The Podfile is a specification that describes the dependencies of the targets of one or more Xcode projects. The Podfile always creates an implicit target, named default,
which links to the first target of the user project. The file should simply be named
Podfile.
A Podfile can be very simple:
pod 'AFNetworking', '~> 2.0'
An example of a more complex Podfile can be:
source 'https://github.com/CocoaPods/Specs.git' source 'https://github.com/Artsy/Specs.git' platform :ios, '8.0' inhibit_all_warnings! xcodeproj 'MyProject' pod 'ObjectiveSugar', '~> 0.5' pod 'Artsy+UILabels', '~> 1.0' target :test do pod 'OCMock', '~> 2.0.1' end post_install do |installer| installer.pods_project.targets.each do |target| puts target.name end end
If you want multiple targets, like adding tests, to share the same pods.
platform :osx, '10.7'
link_with 'MyApp', 'MyApp Tests'
pod 'AFNetworking', '~> 2.0'pod 'Objection', '0.9'
<Specifying
pod versions
When starting out with a project it is likely that you will want to use the latest version of a Pod. If this is the case, simply omit the version requirements.pod 'SSZipArchive'
Later on in the project you may want to freeze to a specific version of a Pod, in which case you can specify that version number.
pod 'Objection', '0.9'
Besides no version, or a specific one, it is also possible to use logical operators:
'> 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
In addition to the logic operators CocoaPods has an optimistic operator
~>:
'~> 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.
For more information, regarding versioning policy, see:
Semantic Versioning
RubyGems Versioning Policies
Finally, instead of a version, you can specify the
:headflag.
This will use the pod’s latest version spec version, but force the download of the ‘bleeding edge’ version. Use this with caution, as the spec might not be compatible with the source material anymore.
pod 'Objection', :head
<Version
Conflicts
Pods often depend on other pods. Conflicts arise when multiple pods depend on different versions of another. Or you may want to tie a dependent pod to a particular version.The conflict error looks like this:
[!] Podfile tries to activate `GoogleAnalytics-iOS-SDK (= 2.0beta4)', but already activated version `3.0' by ARAnalytics/GoogleAnalytics (1.6).
To fix this, you simply add the
GoogleAnalytics-iOS-SDKpod
line before
ARAnalyticsand specify the version:
pod 'GoogleAnalytics-iOS-SDK', '2.0beta4' pod 'ARAnalytics/GoogleAnalytics'
<Using
the files from a folder local to the machine.
If you would like to develop a Pod in tandem with its client project you can use :path.
pod 'AFNetworking', :path => '~/Documents/AFNetworking'
Using this option CocoaPods will assume the given folder to be the root of the Pod and will link the files directly from there in the Pods project. This means that your edits will persist between
CocoaPods installations. The referenced folder can be a checkout of your favourite SCM or even a git submodule of the current repo.
Note that the
podspecof the Pod file is expected to be
in that folder.
<From
a podspec in the root of a library repo.
Sometimes you may want to use the bleeding edge version of a Pod, a specific revision or your own fork. If this is the case, you can specify that with your pod declaration.To use the
masterbranch
of the repo:
pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git'
To use a different branch of the repo:
pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :branch => 'dev'
To use a tag of the repo:
pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :tag => '0.7.0'
Or specify a commit:
pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :commit => '082f8319af'
It is important to note, though, that this means that the version will have to satisfy any other dependencies on the Pod by other Pods.
The
podspecfile
is expected to be in the root of the repo, if this library does not have a
podspecfile
in its repo yet, you will have to use one of the approaches outlined in the sections below.
From: http://guides.cocoapods.org/using/the-podfile.html
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 我的iPhone桌面
- 三种检测iPhone/iPad设备方向的方法
- js判断客户端是iOS还是Android等移动终端的方法
- IOS开发环境windows化攻略
- .net平台推送ios消息的实现方法
- javascript实现根据iphone屏幕方向调用不同样式表的方法
- 探讨Android与iOS,我们将何去何从?
- android Gallery组件实现的iPhone图片滑动效果实例
- Android仿iphone自定义滚动选择器
- Android、iOS和Windows Phone中的推送技术详解
- js判断手机端(Android手机还是iPhone手机)