LoginSignup
3
4

More than 5 years have passed since last update.

cocoapods-keysをSwiftのプロジェクトで利用する

Posted at

概要

Swiftプロジェクトでcocoapods-keysを利用してWebサービスのAPIキー等を管理する際の備忘録

cocoapods-keysについてはこちら

前提

  • bundlerインストール済み
  • Xcode 7.3.1
  • cocoapods 0.39.0
  • cocoapods-keys 1.0.0 (pod)
  • cocoapods-keys 1.6.1 (gemfile)

インストール

リポジトリで cocoapods-keys を利用していることを明示したいのでGemfileで管理する

% cd SwiftyTumblrKit  //iOSアプリのプロジェクトルートディレクトリへ
% touch Gemfile
% vim Gemfile

source 'https://rubygems.org'
gem 'cocoapods-keys', '1.6.1'

% bundle install

keyの追加

Podfileの以下の文を追記、適宜プロジェクト名とキー名を記載し pod installを実行することで対話的にkey-valueを設定できる

Podfileに追加

plugin 'cocoapods-keys', {
  :project => "SwiftyTumblrKit",
  :keys => [
    "consumerKey",
    "secretKey"
  ]}

pod install実行時に Keys (1.0.0)がインストールされなければもう一度pod installを実行する必要がある

Swiftプロジェクトでの利用方法

Swiftプロジェクトで利用する場合は import Keys を追記

既にソースファイルが生成されているので、project名.key名()で呼び出しが可能

今回の例ならば SwiftytumblrkitKeys().consumerKey()でkeyに対応するvalueが返ってくる

import Keys からXcodeの ⌘ + クリック でソースを追ってへッダーファイルを確認するとよい

※Podfileではプロジェクト名をキャメルで記述しているが、生成されたファイル名はキャメルで無い点に注意

参考

3
4
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
3
4