LoginSignup
105
87

More than 5 years have passed since last update.

Cocoapods 1.0.0で注意すること

Last updated at Posted at 2016-05-19

はじめに

Cocoapodsが5月10日に1.0.0をリリースしました。
そこでチーム開発をしていたプロジェクトでエラーが発生したので、共有いたします。

エラー内容

Cocoapodsにターゲット指定が必要になりました。
これまでPodfileは以下のように記載していました。

Podfile
platform :ios,'9.0'
use_frameworks!
pod 'SwiftDate'
pod 'SlideMenuControllerSwift'
pod 'Firebase/Core'
pod 'Firebase/Messaging'
pod 'Firebase/Database'
pod 'Firebase'
pod 'Firebase/Auth'

これでFirebaseがアップデートされたことでpodのほうもアップデートしようと、pod updateのコマンドを打ったところ以下のようなエラーが表示されてしまいました。

[!] The dependency `SwiftDate` is not used in any concrete target.
The dependency `SlideMenuControllerSwift` is not used in any concrete target.
The dependency `Firebase/Core` is not used in any concrete target.
The dependency `Firebase/Messaging` is not used in any concrete target.
The dependency `Firebase/Database` is not used in any concrete target.
The dependency `Firebase` is not used in any concrete target.
The dependency `Firebase/Auth` is not used in any concrete target.

つまり、どのターゲットでもpodが使われていませんよと

エラー対策

そこでターゲット指定を行いました。
Podfileにおいては、Podは以下のような形式でターゲットを指定します。

platform :ios,'9.0'
use_frameworks!
target 'ターゲット先(プロジェクト名やプロジェクトのテスト名)' do
# ここでpod 'hoge'と記載する
end

今回ではこのようにしました。

Podfile
platform :ios,'9.0'
use_frameworks!
target 'ターゲット先(プロジェクト名やプロジェクトのテスト名' do
pod 'SwiftDate'
pod 'SlideMenuControllerSwift'
pod 'Firebase/Core'
pod 'Firebase/Messaging'
pod 'Firebase/Database'
pod 'Firebase'
pod 'Firebase/Auth'
end

このようなことを防ぐために

ターゲットやオプション(platform指定など)を手書きするのは、ミスが起こりやすいですし、なにより面倒くさい。そこで、Cocoapodsにはpod initという便利なコマンドが用意されていますので、かならず使いましょう。
pod initを打つことで、Podfileが自動で生成され、さまざまなオプションもコメントアウトの形で提供されるので、絶対に使いましょう。

以下が、pod initを打つことで生成されるPodfileです

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

target 'Sample' do
  # Comment this line if you're not using Swift and 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
    inherit! :search_paths
    # Pods for testing
  end

end

今回はSampleという名前のプロジェクトでpod initを行いました。

105
87
1

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
105
87