(可選)使用 taobao ruby-china 源替換默認 gem 源: gem source blabla..
ios
$ 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 源git
$ 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 ``` 或者 ```bash $ git clone https://git.coding.net/CocoaPods/Specs.git ~/.cocoapods/repos/master $ pod repo update ``` 切換回官方鏡像 ```bash $ 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文件中有github
source 'https://github.com/CocoaPods/Specs.git'
也須要把它換成repo的源,不然依然是使用GitHub源swift
cd <project_folder>
pod init
編輯 Podfile, examplexcode
# 平臺,必需 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
版本支持:ruby
- `>`, `>=`, `<`, `<=` - `~>`: **up to** next major | minor | patch - `:path` 本地絕對路徑 - `:git` git項目地址,還可以使用 `:branch`, `:tag`, `:commit`
pod install
pod install [package_name]
: 安裝特定版本的 podspod update [package_name]
: 升級 pods 到最新版本brew install carthage
編輯 Cartfile
,好比 SwiftyJSON
bash
github "SwiftyJSON/SwiftyJSON"
carthage update [--platform ios]服務器
$ carthage update *** Fetching SwiftyJSON *** Checking out SwiftyJSON at "4.2.0" *** xcodebuild output can be found in /var/folders/kl/g94q0k_571vdjtcwzzcv20s40000gn/T/carthage-xcodebuild.nN22hg.log *** Building scheme "SwiftyJSON iOS" in SwiftyJSON.xcworkspace *** Building scheme "SwiftyJSON watchOS" in SwiftyJSON.xcworkspace *** Building scheme "SwiftyJSON tvOS" in SwiftyJSON.xcworkspace *** Building scheme "SwiftyJSON macOS" in SwiftyJSON.xcworkspace
Carthage
目錄下:工具
$ tree -L 3 Carthage/ Carthage/ ├── Build │ ├── Mac │ │ ├── SwiftyJSON.framework │ │ └── SwiftyJSON.framework.dSYM │ ├── iOS │ │ ├── 22BD4B6C-0B26-35E1-AF5F-8FB6AEBFD2FD.bcsymbolmap │ │ ├── C862E8A1-24ED-398A-A8E9-A7384E34EDB1.bcsymbolmap │ │ ├── SwiftyJSON.framework │ │ └── SwiftyJSON.framework.dSYM │ ├── tvOS │ │ ├── 1ADB9C1F-36CA-3386-BF07-6EE29B5F8081.bcsymbolmap │ │ ├── SwiftyJSON.framework │ │ └── SwiftyJSON.framework.dSYM │ └── watchOS │ ├── A8A151AB-D15E-3A0B-8A17-BF1A39EC6AB4.bcsymbolmap │ ├── EA427A42-6D21-3FF4-919F-5E50BF8A5D7B.bcsymbolmap │ ├── SwiftyJSON.framework │ └── SwiftyJSON.framework.dSYM └── Checkouts └── SwiftyJSON ├── CHANGELOG.md ├── Example ├── LICENSE ├── Package.swift ├── README.md ├── Source ├── SwiftyJSON.podspec ├── SwiftyJSON.xcodeproj ├── SwiftyJSON.xcworkspace ├── Tests └── scripts
Carthage/Build/iOS
中的 .framework
文件添加到項目中"Build Phases" -> "+" -> "New Run Script Phase"測試
添加這個 Run Script 的做用是爲了讓運行時可以找到這個動態庫。 還能夠將 Carthage 所集成的第三方庫生成的符號文件添加到項目中,這樣咱們在調試的時候,就能夠步入第三方庫內部的代碼:`Build Phrases` -> `New Copy Files Phrase`,將 Carthage/Build/iOS 目錄中的 `SwiftyJSON.framework.dSYM` 符號文件拖動進來
CoaoaPods
是一套總體解決方案,咱們在 Podfile
中指定好咱們須要的第三方庫。而後 CocoaPods
就會進行下載,集成,而後修改或者建立咱們項目的 workspace
文件,這一系列總體操做。
相比之下,Carthage
就要輕量不少,它也會一個叫作 Cartfile
描述文件,但 Carthage
不會對咱們的項目結構進行任何修改,更很少建立 workspace
。它只是根據咱們描述文件中配置的第三方庫,將他們下載到本地,而後使用 xcodebuild
構建成 framework
文件。而後由咱們本身將這些庫集成到項目中。Carthage
使用的是一種非侵入性的哲學。
另外 Carthage
除了非侵入性,它仍是去中心化的,它的包管理不像 CocoaPods
那樣,有一箇中心服務器(cocoapods.org),來管理各個包的元信息,而是依賴於每一個第三方庫本身的源地址,好比 Github。