3
1

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 3 years have passed since last update.

[Swift]最初手こずる?R.swiftのインストール手順

Last updated at Posted at 2022-06-10

はじめに

R.swiftはStoryboardや画像などのリソースを、簡単に取得できるようにする便利なライブラリですが、CocoaPodsやSPMでインストールするだけでいいというわけではありません。

初回導入時に少々手こずったので残しておこうと思います。

Pods

まずはPodfileに以下を追加し、pod install しましょう。

Podfile
pod 'R.swift'

Run Scriptの設定

Target > Build Phases を選択して Run Script を追加します。

"$PODS_ROOT/R.swift/rswift" generate "$SRCROOT/R.generated.swift"

InputFiles,OutputFilesの設定

下記を共に設定します。
スクリーンショット 2022-05-12 21.04.47.png

InputFiles

$TEMP_DIR/rswift-lastrun

OutputFiles

$SRCROOT/generated/R.generated.swift

位置を変える

画像のように、Compile sourcesの上に持ってきます。

※ここが忘れがちなので注意
スクリーンショット 2022-05-12 21.08.07.png

R.generated.swiftをプロジェクトに追加する

上記の作業を終えたら一回ビルドしてみましょう。

そうするとR.generated.swiftというファイルがプロジェクトのルートディレクトリに追加されているので、このファイルをプロジェクトに追加します。(そのままドラック)

スクリーンショット 2022-05-12 21.12.26.png

※.gitignoreに以下を追加するのも忘れずに

*.generated.swift

使用できるか確認する

ViewController
let vc = R.storyboard.main.FooViewController()

Rと打って補完が出てくれば成功です。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?