5
3

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.

CarthageでRswiftを導入する方法(Xcode)

Last updated at Posted at 2020-04-29

はじめに

XcodeにCarthageでRswiftを導入する手順をまとめました。

参考にした記事
https://qiita.com/nesskazu/items/38e1e325392780b65ce4
https://github.com/mac-cain13/R.swift (Manuallyの部分)
https://qiita.com/lovee/items/5617cdaa28a470b141c2

1. Carthageをインストール

まずCartthageを導入する。
https://qiita.com/yutat93/items/97fe9bc2bf2e97da7ec1

Cartfileを作成する。

ターミナル
$touch Cartfile

2. Rswiftをインストール

作成したCartfileに下記をコピペ。

Cartfile
github "mac-cain13/R.swift.Library"

スクリーンショット 2020-04-29 18.17.58.png

ターミナルでcarthage updateを実行。

ターミナル
$carthage update

プロジェクトのCarthage/Build/iOSに、Rswift.frameworkが生成される。

3. Xcodeでの設定

①Generalにフレームワークを追加
プロジェクトをクリック→GeneralのFrameworks, Libraries, and Embedded ContentにRswift.frameworkを追加。
(FinderからCarthage/Build/iOSと移動し、Rswift.frameworkをドラッグ&ドロップ)
スクリーンショット 2020-04-29 18.25.27.png

②Scriptを2つ追加する
Build Phases → +ボタン → NewRunScriptPhaseを押す。
スクリプトに

/usr/local/bin/carthage copy-frameworks

を追加して、さらにInput Filesに

$(SRCROOT)/Carthage/Build/iOS/Rswift.framework

を追加する。
スクリーンショット 2020-04-29 18.31.41.png

もう一度Build Phases → +ボタン → NewRunScriptPhaseを押す。
スクリプトに

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

を追加して、Input Filesに

$TEMP_DIR/rswift-lastrun

Output Filesに

$SRCROOT/R.generated.swift

を追加する。
追加したら2つ目のscriptをCompile Sourcesの上にドラッグ&ドロップで移動させる。
497683_7c2ebc46-6a83-4456-7288-da9e5540c43d.png

③rswiftをダウンロード
下記から最新のrswift-v-.zipをダウンロードする。
https://github.com/mac-cain13/R.swift/releases
スクリーンショット 2020-04-29 19.58.22.png

下記の2つのファイルをプロジェクトのrootに追加する。(rootじゃないとビルドできないので注意してください。)
スクリーンショット 2020-04-29 18.30.06.png

4.ビルド

ビルドするとR.generated.swiftが生成されるのでプロジェクト内に移動させる。
スクリーンショット 2020-04-29 18.33.00.png

5. .gitignoreに追加

.gitignore
# R.swift
*.generated.swift

おわりに

これでRswiftの導入は完了です。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?