Can't Experiment SwiftNIO in Playground


(Kevin) #1

Generally I can do as following steps to experiment a swift package in a macOS Playground:

  1. clone the project
  2. use 'swift package generate-xcodeproj' to generate a Xcode project
  3. go to "File -> Save As Workspace..." generate a Xcode workspace
  4. add a macOS Playground into the workspace
  5. in the Playground import the package and start to experiment it
    But when I try to experiment swift-nio, I got "error: missing required module 'CNIOAtomics' "
    how can I fix this?

(Tony Y) #2

I think you must create a module.modulemap of CNIOAtomics.


(Cory Benfield) #3

You may also want to verify that the "Enable Modules (C and Objective-C)" setting is on, though I have no idea how to do that verification for playgrounds.


(Johannes Weiss) #4

@dokun1 recently made a live demo of a playground with SwiftNIO, it's more annoying than you'd hope to get it working but in the end it did :).

http://www.okun.io/2018/08/02/live-demo-swift-nio/


(Johannes Weiss) #5

@lukasa just added Cocoapods support and now that's actually super easy:

  1. Create a new Xcode project for macOS
  2. pod init
  3. edit Podfile and put
  pod 'SwiftNIO'
  pod 'SwiftNIOTransportServices'

there

  1. pod install
  2. close the Xcode project
  3. open the Xcode workspace created by Cocoapods
  4. File -> New -> Playgrond, select Blank
  5. put import NIO and probably import NIOTransportServices in the playground

and you're done :)


(Kevin) #6

That's great, thanks for your work!


(Johannes Weiss) #7

Btw, I think that's a bug in the Xcode projects SwiftPM generates so I filed SR-9024 for that.


(Johannes Weiss) #8

It turns out I was actually wrong and SwiftPM already had everything we need but NIO's C modules didn't have proper umbrella modules, thanks to @Aciid for pointing this out! That's fixed in swift-nio#636 and should be released soon.

After that you can run swift package generate-xcodeproj inside SwiftNIO and drag the generated Xcode projects into any of your Xcode projects and it will work. It will also work in a playground :slight_smile: .


(Johannes Weiss) #9

and finally: this has been released with SwiftNIO 1.10.0 so I would expect Xcode projects and playgrounds that contain SwiftNIO sub-projects to work now. If not, please report back here or file an issue on NIO's github.


(Kevin) #10

really appreciate your work!