您的位置:首页 > 移动开发 > IOS开发

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 
:head
 flag.
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-SDK
 pod
line before 
ARAnalytics
 and 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 
podspec
 of 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 
master
 branch
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 
podspec
 file
is expected to be in the root of the repo, if this library does not have a 
podspec
 file
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  xcode iphone ios cocoapods