Xcode中使用cocoapods
安装cocoapods
需要ruby最低版本1.9.3,如当前mac系统的ruby的版本较低则需要安装高版本。
打开终端,执行下面命令安装cocoapods。(需要输入管理员密码)
sudo gem install cocoapods
也可以输入下面指令判断cocoapods安装是否成功:
pod search afnetworking
如果没有安装成功,提示Setting up CocoaPods master repo。也可以输入which pod有路径显示就证明安装成功
使用cocoapods
首先进行初始化,终端中cd 到项目文件夹,然后执行pod init
。
在工程目录下生成Podfile文件。
可通过vim Podfile
进行编辑文件,也可直接通过文本查看器打开。
接下来安装库,在Podfile中添加 pod ‘库名’ 并保存。
pod ‘SocketRocket’
完整的文件内容如下:
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'WebSocketTest' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for WebSocketTest
pod 'SocketRocket'
target 'WebSocketTestTests' do
inherit! :search_paths
# Pods for testing
end
target 'WebSocketTestUITests' do
# Pods for testing
end
end
输入pod install
安装库,安装成功则提示Pod installation complete。
接下来就可以在Xcode中使用依赖库了。