Swift筆記 使用CocoaPods來添加開源庫

使用Pod可以方便的給程序添加一些開源庫,使開發更有效率。
在自己所建立的ios的swift工程文件目錄下,執行如下。

CocoaPods 版本升級

$ sudo gem install cocoapods --pre
$ pod --version
0.36.0.beta.2

生成 Podfile

$ pod init
$ vi Podfile
source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '8.0'

target 'XXXXX' do
end

target 'XXXXXTests' do

end

在Podfile中添加要導入的庫

  pod 'Alamofire'
  pod 'SwiftyJSON'
  pod 'Alamofire-SwiftyJSON', :git => "https://github.com/SwiftyJSON/Alamofire-SwiftyJSON.git"

安裝

pod install

這個時候會在工程文件同一級生成一個Workspace文件,雙擊workspace文件,就可以打開自己的工程和添加的庫了。

維護

今後需要添加或刪除一些開源庫時,需要關掉Xcode。
然後修改Podfile,然後執行install就可以了。
非常的方便

遇到的錯誤1

[!] Pods written in Swift can only be integrated as frameworks; this feature is still in beta. Add `use_frameworks!` to your Podfile or target to opt into using it

在podfile文件裏添加

use_frameworks!

錯誤2

執行install後,長時間沒有反應。

$ pod install
Updating local specs repositories

將Local的

$ pod repo remove master
Removing spec repo `master`
$ pod setup
Setting up CocoaPods master repo
Setup completed
$ pod install
Updating local specs repositories
Analyzing dependencies
Downloading dependencies
(中略)
Generating Pods project
Integrating client project
Sending stats

參照:
http://d.akiroom.com/2015-08/pod-install-forever/
http://qiita.com/yokomotod/items/884f624cf17ba4a5ef11

發佈了34 篇原創文章 · 獲贊 43 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章