【问题标题】:How to import RxSwift in Playground of xcode?如何在 xcode 的 Playground 中导入 RxSwift?
【发布时间】:2017-02-07 06:08:20
【问题描述】:

我正在尝试通过以下方式在 xcode 游乐场中导入 rxswift:

gem install cocoapods-playgrounds

然后

pod playgrounds RxSwift

但这并没有发生。怎么做?

【问题讨论】:

  • 您可以为任何项目添加游乐场。如果你知道如何安装 RxSwift pod,那么你很好......

标签: swift xcode cocoapods rx-swift


【解决方案1】:
  1. 您应该在您的计算机上克隆RxSwift repository
  2. 打开Rx.xcworkspace
  3. 构建RxSwift-macOS 方案
  4. Rx.xcworkspace 树视图中打开Rx.playground 并添加新页面
  5. import RxSwift 在新页面中。
  6. 选择View > Debug Area > Show Debug Area

【讨论】:

  • 我会尽力让您对此提供反馈
  • @JasonBourne 我附上一些图片来指导你一步一步
【解决方案2】:

超级简单:

  1. 新建一个项目,Xcode菜单>文件>新建>项目...(单 查看应用程序)
    1. 关闭 Xcode
    2. 在新项目中初始化 pod(终端中的 pod init)
    3. 编辑 Podfile,添加 RxSwift、RxCocoa
    4. 安装 pod(在终端中安装 pod)
    5. 打开由 CocoaPods 创建的 RxSwiftProject.xcworkspace
    6. 使用默认方案构建和运行项目
    7. 添加一个新的 Playground,Xcode 菜单 > File > New > Playground...
    8. 选择 Add to: RxSwiftProject ,将其添加到 RxSwift 工作区
    9. 将其保存在工作区文件夹中

example code here

【讨论】:

  • 请用适当的技术标记问题。让工作的人对于这个问题,请标记swiftios
【解决方案3】:

正如@sas 所暗示的,您可以使用Arena

更具体一点:


安装Arena的一行代码:

brew install finestructure/tap/arena

一行来创建启用 RxSwift 的 Playground:

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

结果:

➡️  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'

完成!打开 Arena-Playground 并找到您的 Playground(可能称为 MyPlayground),在那里进行编码。第一次可能需要点击产品 -> 构建才能开始。

【讨论】:

    【解决方案4】:

    在 Xcode 9.1 中不再工作

    $ pod playgrounds RxSwift,RxCocoa

    给予

    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

    【讨论】:

      【解决方案5】:

      您可以使用Arena 使用 3rd 方 SPM 库创建一个 Playground:

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

      这也应该适用于 RxSwift。

      【讨论】:

        【解决方案6】:

        @Jason,你需要运行以下命令:

        $ gem install cocoapods-playgrounds

        $ pod playgrounds RxSwift,RxCocoa

        它会起作用的。第二个命令打开一个已添加 pod 的工作区。只要记住先建立一个目标,然后你就可以玩你的新游乐场了。

        【讨论】:

        • 现在不工作了。 pod 游乐场 RxSwift,RxCocoa。为什么? Errno::ENOENT - 没有这样的文件或目录@ dir_initialize - /Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File Templates/Source/Playground with Platform Choice.xctemplate...
        【解决方案7】:

        就是这么简单!

        1. 在你的项目中创建playground(当然需要添加RxSwift的依赖)

        2. 在 Xcode 项目导航中,在 Playground 文件下方,您会找到一个名为 source 的文件夹

        3. 在此文件夹中创建此 swift 文件: https://github.com/ReactiveX/RxSwift/blob/master/Rx.playground/Sources/SupportCode.swift

        4. 那就尽情享受吧!

          // example
          
          import RxSwift
          
          playgroundShouldContinueIndefinitely()
          
          example("of") {
          
          let disposeBag = DisposeBag()
          
          Observable.of("?", "?", "?", "?")
              .subscribe(onNext: { element in
                  print(element)
              })
          }
          

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-02-21
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-08-20
          相关资源
          最近更新 更多