【Swift】CocoaPodsのインストール
今回はMacにCocoaPodsをインストールするところまでをこの記事で説明します。
この記事のポイント・環境構築
・ライブラリ導入(Podfileの作成、編集)
・インストール
・ライブラリ導入(Podfileの作成、編集)
・インストール
環境構築
CocoaPodsを設定します。 ターミナルで以下のコマンドを入力します。
sudo gem install cocoapods
または
sudo gem install -n /usr/local/bin cocoapods
または
sudo gem install -n /usr/local/bin cocoapods
インストールが終わったら、次に以下のコマンドを入力します。
pod setup
これで環境構築は完了です。
ライブラリ導入
まずターミナルから、プロジェクトファイルまで移動しましょう。
Podfileの作成
プロジェクトファイルを選択後、以下のコマンドを入力します。
※プロジェクトファイルを一度、ビルトしてからでないとPodfileが作成されなかったはず…
すみません。うろ覚えです。
pod init
このコマンドでPodfileが自動的に作成されます。 生成されたPodfileの中身は以下の通りです。
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'sample' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for sample
target 'sampleTests' do
inherit! :search_paths
# Pods for testing
end
target 'sampleUITests' do
# Pods for testing
end
end
# platform :ios, '9.0'
target 'sample' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for sample
target 'sampleTests' do
inherit! :search_paths
# Pods for testing
end
target 'sampleUITests' do
# Pods for testing
end
end
Podfileの編集
Podfileを以下のように編集します。※今回はSwiftyJSONをインストールします。
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'sample' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
pod 'SwiftyJSON' ←ここに追加
# Pods for sample
target 'sampleTests' do
inherit! :search_paths
# Pods for testing
end
target 'sampleUITests' do
# Pods for testing
end
end
# platform :ios, '9.0'
target 'sample' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
pod 'SwiftyJSON' ←ここに追加
# Pods for sample
target 'sampleTests' do
inherit! :search_paths
# Pods for testing
end
target 'sampleUITests' do
# Pods for testing
end
end
バージョンを指定したい場合は以下のように設定します。
pod 'SwiftyJSON', '~> 1.1.5'
これでライブラリの導入は完了です。
|
インストール
初めてプロジェクトにインストールする場合は以下のコマンドを入力します。
pod install
2回目以降(追加、削除)の場合は以下のコマンドを入力します。
pod update
インストールが完了するとターミナルに以下のようなメッセージが表示されます。
Analyzing dependencies
Downloading dependencies
Installing SwiftyJSON (5.0.0)
Generating Pods project
Integrating client project
[!] Please close any current Xcode sessions and use `sample.xcworkspace` for this project from now on.
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.
Downloading dependencies
Installing SwiftyJSON (5.0.0)
Generating Pods project
Integrating client project
[!] Please close any current Xcode sessions and use `sample.xcworkspace` for this project from now on.
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.
これでインストールは完了です。