LoginSignup
6
6

More than 5 years have passed since last update.

ParseをcocoaPodsで導入方法

Posted at

はじめに

通信系アプリを作成するにあたって、インフラ・サーバサードの構築などをするのがあまりにも手間なので、ParseというSDKを導入した時の話です。(本OS環境はOS X El Capitan)

「『Parse』とは何?」という方は下記リンク先の記事をご覧ください。

cocoaPodsの導入

cocoaPodsをまだ導入していない方は、ホームディレクトリで以下を実行します。

$ gem install cocoapods

これで今後はcocoaPodsの機能を扱えます。

プロジェクトにcocoaPodsをセットアップ

作成したプロジェクトにターミナルで移動します。
下記の例はデスクトップに「sampleApp」というプロジェクトを作成した場合です。

example
$ cd ~/Desktop/sampleApp

そして、次にセットアップをします。

$ pod setup

これで完了です。もし

$ zsh: command not found pod

というエラーが出る方は下記リンク先の記事を参考にしてください。

Podfileの作成

続いて、次のコマンドを実行してください。

$ pod init

このコマンドで初期化が実行され、Podfileが作成されます。
ここでPodfileを覗くと下記のようになっていると思います。
(ただし、xcodeやcocoaPodsのバージョン等によって違うので必ず同じものではない。)

Podfileの例
# Uncomment this line to define a global platform for your project
# platform :ios, '8.0'
# Uncomment this line if you're using Swift
# use_frameworks!

target 'sampleApp' do

end

target 'sampleAppTests' do

end

target 'sampleAppUITests' do

end

このようにPodfileをターミナル上で見るにはcatコマンドを使います。

$ cat Podfile

Parseを導入

ようやく本題ですが、Parseを導入していきます。
今回はvimコマンドでPodfileを書き換えていきます。

$ vim Podfile

最初は観覧モードなので、キーボードの「i」を押して編集モードに変更します。

そして、次のように上記の「Podfileの例」を変更します。

Podfileの例
# Uncomment this line to define a global platform for your project
# platform :ios, '8.0'
# Uncomment this line if you're using Swift
# use_frameworks!

target 'sampleApp' do
 pod 'Parse'
end

target 'sampleAppTests' do

end

target 'sampleAppUITests' do

end

そして、保存するために一度編集モードを抜けないといけないので、キーボードの「esc」を押して観覧モードに戻り、キーボードで「:wq」と入力し「enter(return)」を押して保存完了し'vim'を終了します。

ちなみに、

「:w」で書き込んで保存
「:q」でvimを終了
「:wq」で書き込んで保存し、vimを終了

という意味のコマンドです。

さて、話を戻して。次に下記のコマンドで上記の「Podfile」の情報を元にParseを対象のプロジェクト(今回で言えば「sampleApp」)に導入します。

$ pod install

ここで、もしxcodeで対象のプロジェクト(今回で言えば「sampleApp」)を開いている場合はプロジェクトを一度閉じてください。でないとpodが「sampleApp」プロジェクトを編集しにいけません。

また、この時

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.

という警告?が出る人がいるかもしれません。
その方は下記のリンク先の記事を参考にしてください。

以上で導入は終わりです。

LINK

今回に限らずcocoaPod導入する際に参考にしたサイト
SwiftでParseを利用した時のことについて書かれた記事
6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6