

iOS 实战 - CocoaPods
source link: http://blog.danthought.com/programming/2015/06/07/cocoapods/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

iOS 实战 - CocoaPods
CocoaPods 是为了解决 Swift 和 Objective-C 项目的依赖关系,在没有 CocoaPods 以前,我们只能手动地拷贝第三方的代码,维护起来很麻烦,CocoaPods 是通过 Ruby 语言编写的,自然在设计和使用上非常类似于 RubyGems。
安装 CocoaPods
因为 CocoaPods 用 Ruby 语言编写的,所以先要安装 Ruby,参考文章 开始学习 Ruby,接下来通过 RubyGems 安装 CocoaPods。
$ gem install cocoapods
维护依赖关系
首先在 Xcode 项目的根目录运行如下命令来初始化:
$ pod init
编辑 Podfile,写入如下内容:
platform :ios, '8.0'
use_frameworks!
target 'MyApp' do
pod 'AFNetworking', '~> 2.5'
pod 'ORStackView', '~> 2.0'
pod 'SwiftyJSON', '~> 2.1'
end
运行如下命令安装依赖:
$ pod install
通过打开 Xcode 工作空间来构建项目:
$ open App.xcworkspace
现在就可以在项目中导入依赖:
#import <Reachability/Reachability.h>
如果你觉得以上思考对你有帮助,请订阅博客
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK