Swift笔记 使用CocoaPods来添加开源库

来源:互联网 发布:linux select c代码 编辑:程序博客网 时间:2024/06/05 08:55

使用Pod可以方便的给程序添加一些开源库,使开发更有效率。
在自己所建立的ios的swift工程文件目录下,执行如下。

CocoaPods 版本升级

$ sudo gem install cocoapods --pre$ pod --version0.36.0.beta.2

生成 Podfile

$ pod init$ vi Podfilesource 'https://github.com/CocoaPods/Specs.git'platform :ios, '8.0'target 'XXXXX' doendtarget 'XXXXXTests' doend

在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 installUpdating local specs repositories

将Local的

$ pod repo remove masterRemoving spec repo `master`$ pod setupSetting up CocoaPods master repoSetup completed$ pod installUpdating local specs repositoriesAnalyzing dependenciesDownloading dependencies(中略)Generating Pods projectIntegrating client projectSending stats

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

0 0
原创粉丝点击