How to import RxSwift in Playground of xcode?

it's super easy:

  1. Create a new project, Xcode menu > File > New > Project… (Single View App)
    1. Close Xcode
    2. Initialize pods in the new project (pod init in terminal)
    3. Edit Podfile, add RxSwift, RxCocoa
    4. Install pods (pod install in terminal)
    5. Open RxSwiftProject.xcworkspace created by CocoaPods
    6. Build and run project using default scheme
    7. Add a new playground, Xcode menu > File > New > Playground…
    8. Select Add to: RxSwiftProject , to add it to the RxSwift workspace
    9. Save it in the workspace folder

example code here


No longer works in Xcode 9.1

$ pod playgrounds RxSwift,RxCocoa

gives

Errno::ENOENT - No such file or directory @ dir_initialize - /Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File Templates/Source/Playground with Platform Choice.xctemplate


  1. You should clone the RxSwift repository on your computer
  2. Open Rx.xcworkspace
  3. Build the RxSwift-macOS scheme
  4. Open Rx.playground in the Rx.xcworkspace tree view and add a new page
  5. import RxSwift in the new page.
  6. Choose View > Debug Area > Show Debug Area

steps 3 and 4

step 5


As @sas has hinted at, you can use Arena.

To be more specific:


One line to install Arena:

brew install finestructure/tap/arena

One line to create your RxSwift enabled Playground:

arena https://github.com/ReactiveX/RxSwift

Results:

➡️  Package: https://github.com/ReactiveX/RxSwift @ from(5.1.1)
🔧 Resolving package dependencies ...
📔 Libraries found: RxSwift, RxCocoa, RxRelay, RxBlocking, RxTest
🔨 Building package dependencies ...
✅ Created project in folder 'Arena-Playground'

Done! Open Arena-Playground and find your Playground (probably called MyPlayground), code there. It may require a click on Product -> Build to get going the first time.