LoginSignup
5
4

More than 3 years have passed since last update.

playgroundでRxSwiftを試す

Last updated at Posted at 2020-08-04

何をやりたいか

RxSwiftの勉強を始めたばかりで、
とりあえずplaygroundでサンプルコードを実行したいと思いますが、
ライブラリのimportがうまくいかなかったので、メモとして残します。
少しでも役に立てれば幸いです。

結論

playgroundでimportする前に、一回プロジェクトをビルドする必要があるかもしれないです。

やり方

新規プロジェクトの作成

iOSのSingle View APPを選択して、適当な名前をつけて作成します。
そしてプロジェクトを閉じて、ターミナルでライブラリの導入をやります。

ライブラリの導入

導入するのによく使われているツールはCocoaPods、Carthage、Swift Package Managerがありますが、今回はCocoaPodsで入れます。

  • CocoaPodsをインストール
  • プロジェクトのルートディレクトリに移動し、pod initでPodfileファイルを生成
  • Podfileファイルに必要なライブラリを記入
target 'LearnRxSwift' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!

# Pods for LearnRxSwift
pod 'RxSwift', '~> 5'
pod 'RxCocoa', '~> 5'

end
  • pod installでインストール開始(2回目以降はpod update)
  • エラーがなければこれでインストール完了

playgroundファイルの作成

  • CocoaPodsが作成してくれたプロジェクト名.xcworkspaceワークスペースを開く
  • 一回ビルドします(デフォルトの設定でも良い)
  • 図のようにルートにplaygroundを作りたいので、commandキーを押しながら、選択中のものをクリックして、選択状態を解除します
    スクリーンショット 2020-08-04 15.17.45.png
  • メニューバーから、File > New > File... > iOSで一番下のBlankのplaygroundを選択して生成します。
  • これでimportができるようなる

参考リンク

How to import RxSwift in Playground of xcode?
Testing RxSwift code in Playgrounds using tappable buttons bound with RxCocoa

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