LoginSignup
16
16

More than 5 years have passed since last update.

Podfileの書き方変わったし、Podfileをきれいにまとめて書く。

Posted at

cocoapodsのversion 1.0にupdateしたらPodfileの書き方が変わるので、ついでにPodfileを書き換えまえす。

あと、PodfileはRubyで書かれてるということが分かれば、少しきれいに書ける!ということが最近わかったので備忘録として。

作り直すので削除!の前に現状のコピー取っておく!

pod 'PromiseKit', '3.0.1'...のあたりは別でファイルにコピーとっておきましょう!(๑˃̵ᴗ˂̵)و

コピーできたらファイル消してpod init

rm -rf Podfile

pod init

podfile消して、pod initしたほうがちゃんとテンプレが作り直されるので、最新の形式に基づいて書ける。

ターゲットいっぱいあるのでアプリだと、

target 'ProjectName-iOS-AdHoc' do

end

がいっぱいある。

target 'ProjectName-iOS-Debug' do
    pod 'PromiseKit', '3.0.1'
end

target 'ProjectName-iOS-AdHoc' do
    pod 'PromiseKit', '3.0.1'
end

target 'ProjectName-iOS-Release' do
    pod 'PromiseKit', '3.0.1'
end

こんな風に複数のターゲットに同じPodをインストールする際に何度も書くのはよろしくない。(コピー漏れしそうだし。)

共通部分は定数にまとめて、各ターゲットはその定数をinstall。

# Uncomment this line to define a global platform for your project
platform :ios, '9.0'
use_frameworks!

# インストールするpodをまとめた定数
def install_pods
  pod 'PromiseKit', '3.0.1'
  pod 'FrameAccessor', '2.0'
  pod 'LUKeychainAccess', '1.2.5'
  ........
end

# あとは定数をinstall
target 'ProjectName-iOS-AdHoc' do
    install_pods
end

target 'ProjectName-iOS-AdHocRelease' do
    install_pods
end

target 'ProjectName-iOS-Debug' do
    install_pods
end

target 'ProjectName-iOS-Release' do
    install_pods,
    pod 'GoogleAnalytics', '~> 3.13'
end

target 'ProjectName-iOS-Store-AdHoc' do
    install_pods
end

target 'ProjectName-iOS-Store-Debug' do
    install_pods
end

target 'ProjectName-iOS-Store-Release' do
    install_pods
end

こう書けば、基本的にはinstall_podsの中に追加していけばOKだし、特定のtargetにだけ入れたいpodも探しやすい。

参考

[http://qiita.com/shn/items/e656fe5452e02c0b2853:embed:cite]

↑だと

def install_pods do
end

になってるけど、

syntax error, unexpected keyword_end, expecting end-of-input.

でて怒られたんだけど、

def install_pods
end

でOK。
定数宣言だからdoはいらないんだろうね。

でも参考記事ありがとうございました!(∀`*)ゞ

16
16
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
16
16