18

I am trying to import rxswift in xcode playground by this:

gem install cocoapods-playgrounds

and after that

pod playgrounds RxSwift

But it is not happening. How to do it?

Raunak
  • 3,314
  • 1
  • 22
  • 28
Istiak Morsalin
  • 10,621
  • 9
  • 33
  • 65
  • You can add a playground to any project. If you know how to install the RxSwift pod then you are good... – mfaani Nov 02 '19 at 01:45

7 Answers7

28
  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

xandrefreire
  • 2,276
  • 14
  • 18
8

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

  • Please do tag the question with appropriate technology. So that people working For this question, please tag `swift`, `ios`. – Surya Oct 11 '19 at 13:30
2

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.

Mete
  • 5,495
  • 4
  • 32
  • 40
1

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

user6902806
  • 280
  • 1
  • 12
1

You can create a playground with 3rd party SPM libraries with Arena:

arena https://github.com/finestructure/Gala
  resolving package dependencies
  libraries found: Gala
✅  created project in folder 'SPM-Playground'

That should work for RxSwift as well.

sas
  • 7,017
  • 4
  • 36
  • 50
0

@Jason, you need to run following commands:

$ gem install cocoapods-playgrounds

$ pod playgrounds RxSwift,RxCocoa

and it'll work. The second command opens a workspace with already added pods. Just remember to first build a target and then you can play with your new playground.

  • 4
    Does not work now. pod playgrounds RxSwift,RxCocoa. Why? 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... – Pedro.Alonso May 03 '18 at 22:55
-1

That so easy!

  1. Create playground in your project(of course you need to need to add the dependency of RxSwift)

  2. In Xcode project navigation, below the playground file, you will find a folder named source

  3. Create this swift file in this folder: https://github.com/ReactiveX/RxSwift/blob/master/Rx.playground/Sources/SupportCode.swift

  4. Then enjoy it!

    // example
    
    import RxSwift
    
    playgroundShouldContinueIndefinitely()
    
    example("of") {
    
    let disposeBag = DisposeBag()
    
    Observable.of("", "", "", "")
        .subscribe(onNext: { element in
            print(element)
        })
    }
    
Heefan
  • 385
  • 2
  • 8
JunYao Yuan
  • 223
  • 1
  • 6