内容简介:相比之下,另外
CoaoaPods
是一套整体解决方案,我们在 Podfile
中指定好我们需要的第三方库。然后 CocoaPods
就会进行下载,集成,然后修改或者创建我们项目的 workspace
文件,这一系列整体操作。
相比之下, Carthage
就要轻量很多,它也会一个叫做 Cartfile
描述文件,但 Carthage
不会对我们的项目结构进行任何修改,更不多创建 workspace
。它只是根据我们描述文件中配置的第三方库,将他们下载到本地,然后使用 xcodebuild
构建成 framework
文件。然后由我们自己将这些库集成到项目中。 Carthage
使用的是一种 非侵入性
的哲学。
另外 Carthage
除了非侵入性,它还是去中心化的,它的包管理不像 CocoaPods
那样,有一个中心服务器(cocoapods.org),来管理各个包的元信息,而是依赖于每个第三方库自己的源地址,比如 Github。
Cocoapods
安装
-
(可选)使用
taobaoruby-china 源替换默认 gem 源:gem source blabla..
$ gem sources -l *** CURRENT SOURCES *** https://rubygems.org/ $ gem sources --remove https://rubygems.org/ https://ruby.taobao.org/ removed from sources $ gem source -a https://gems.ruby-china.com/ https://gems.ruby-china.com/ added to sources $ gem source -c *** Removed specs cache *** $ gem source -u source cache successfully updated $ gem sources -l *** CURRENT SOURCES *** https://gems.ruby-china.com/
-
sudo gem install cocoapods
-
(可选)切换 pod 源
$ pod repo master - Type: git (master) - URL: https://github.com/CocoaPods/Specs.git - Path: /Users/qiwihui/.cocoapods/repos/master $ pod repo remove master $ pod repo add master https://git.coding.net/CocoaPods/Specs.git $ pod repo update $ pod setup
或者
$ git clone https://git.coding.net/CocoaPods/Specs.git ~/.cocoapods/repos/master $ pod repo update
$ pod repo remove master $ pod repo add master https://github.com/CocoaPods/Specs.git $ pod repo update Updating spec repo `master` $ /usr/local/bin/git -C /Users/qiwihui/.cocoapods/repos/master fetch origin --progress remote: Enumerating objects: 511, done. remote: Counting objects: 100% (511/511), done. remote: Compressing objects: 100% (134/134), done. remote: Total 820 (delta 399), reused 449 (delta 367), pack-reused 309 Receiving objects: 100% (820/820), 99.24 KiB | 401.00 KiB/s, done. Resolving deltas: 100% (501/501), completed with 194 local objects. From https://github.com/CocoaPods/Specs 5b04790953c..e3ba7ee3a29 master -> origin/master $ /usr/local/bin/git -C /Users/qiwihui/.cocoapods/repos/master rev-parse --abbrev-ref HEAD master $ /usr/local/bin/git -C /Users/qiwihui/.cocoapods/repos/master reset --hard origin/master HEAD is now at e3ba7ee3a29 [Add] IOS_OC_BASIC 6.3 CocoaPods 1.6.0.beta.2 is available. To update use: `sudo gem install cocoapods --pre` [!] This is a test version we'd love you to try. For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.6.0.beta.2
-
如果Podfile文件中有
source 'https://github.com/CocoaPods/Specs.git'
也需要把它换成repo的源,否则依然是使用GitHub源
基础用法
-
cd <project_folder>
-
pod init
-
编辑 Podfile, example
# 平台,必需 platform :ios, '9.0' # 隐藏警告 inhibit_all_warnings! target 'AlamofireDemo' do # Using Swift and want to use dynamic frameworks use_frameworks! # 项目 Pods pod 'Alamofire', '~> 4.5' target 'AlamofireDemoTests' do inherit! :search_paths # 测试 Pods end end
版本支持: - `>`, `>=`, `<`, `<=` - `~>`: **up to** next major | minor | patch - `:path` 本地绝对路径 - `:git` git项目地址,还可使用 `:branch`, `:tag`, `:commit`
-
pod install
- Always 打开项目下 *.xcworkspace 文件作为项目入口
pod install 和 pod update 区别
pod install [package_name] pod update [package_name]
Carthage
安装
brew install carthage
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。