1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

CocoaPodsを用いたライブラリの導入方法(例としてSwiftyGifの導入)

Posted at

swiftでのアプリケーション勉強時に、CocoaPodsを用いた方法でライブラリを追加したので、忘れぬようにアウトプット

目的

CocoaPodsを用いたライブラリの導入

今回の自分の環境

  • Apple M1
  • macOS 13.2.1
  • xcode 14.2

CocoaPodsのインストール

command+スペースでターミナル(iTerm導入済みの方はそちらでもOK)を開く

ターミナル
~ % sudo gem install cocoapods

passwordが求められるので、macログイン時のパスワードを入力
passwordは非表示で入力されます

ターミナル
Password:

installedと出てればインストールは完了

ターミナル
~ 省略
 6 seconds
28 gems installed

セットアップの実行

ターミナル
 ~ %  pod setup

以下の表記が出ればOK

ターミナル
Setup completed

CocoaPodsを用いてライブラリを導入する

まず導入したいアプリケーションの有るフォルダに移動する
例として、desktop/documents/xcode内にあるswiftTrainingが導入したいアプリケーションである場合は以下のように入力

ターミナル
~ % cd documents/xcode/swiftTraining

アプリケーションまで移動したらpod initを入力

ターミナル
アプリケーション名 % pod init

open Podfileと入力、もしくはPodfileを直接開いてもOK

ターミナル
アプリケーション名 % open Podfile

Podfileが開いたら導入したいライブラリを入力、今回はgifを扱うSwiftyGifを導入
README.mdの指示通りに記述

podfile
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'アプリケーション名' do
  # Comment the next line if you don't want to use dynamic frameworks
  source 'https://github.com/CocoaPods/Specs.git' //追記
  use_frameworks!
  pod 'SwiftyGif' //追記
  # Pods for create-action
end

保存したらターミナルでpod installと入力

ターミナル
アプリケーション名 % pod install

特にエラーが起きなければ導入は完了

アプリケーションを開き直す

この時、XcodeのOpen a project or fileで開き、アプリケーション名.xcworkspaceと書かれた方のファイルを選択して開くこと
※アプリケーション名.xcodeprojは、ライブラリが入っていないプロジェクト
アプリケーション名.xcworkspaceは、ライブラリが入っているプロジェクトであるため。
スクリーンショット_xcode
スクリーンショット_xcode

以上でライブラリが導入できたかと思います!

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?