Can't Experiment SwiftNIO in Playground

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?

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

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.

@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 :).

1 Like

@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 :)

5 Likes

That's great, thanks for your work!

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

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: .

4 Likes

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.

1 Like

really appreciate your work!

I want to sketch up a prototype based on HTTP1Server example so I created a Workspace in Xcode 11.5, cloned Swift-NIO and added it to a new Workspace as project. Although NIO builds fine the Playground having HTTP1Server main code fails with the following error below:

error: Couldn't lookup symbols:
  protocol witness table for NIOHTTP1Server.HTTPHandler : NIO.ChannelHandler in NIOHTTP1Server
  protocol witness table for NIOHTTP1Server.HTTPHandler : NIO.ChannelHandler in NIOHTTP1Server
  protocol witness table for NIOHTTP1Server.HTTPHandler : NIO.ChannelHandler in NIOHTTP1Server
  protocol witness table for NIOHTTP1Server.HTTPHandler : NIO.ChannelHandler in NIOHTTP1Server
  protocol witness table for NIOHTTP1Server.HTTPHandler : NIO.ChannelHandler in NIOHTTP1Server
  protocol witness table for NIOHTTP1Server.HTTPHandler : NIO.ChannelHandler in NIOHTTP1Server
  protocol witness table for NIOHTTP1Server.HTTPHandler : NIO.ChannelHandler in NIOHTTP1Server
  protocol witness table for NIOHTTP1Server.HTTPHandler : NIO.ChannelHandler in NIOHTTP1Server
  protocol witness table for NIOHTTP1Server.HTTPHandler : NIO.ChannelHandler in NIOHTTP1Server
  protocol witness table for NIOHTTP1Server.HTTPHandler : NIO.ChannelHandler in NIOHTTP1Server
  protocol witness table for NIOHTTP1Server.HTTPHandler : NIO.ChannelHandler in NIOHTTP1Server
  protocol witness table for NIOHTTP1Server.HTTPHandler : NIO.ChannelHandler in NIOHTTP1Server
  protocol witness table for NIOHTTP1Server.HTTPHandler : NIO.ChannelHandler in NIOHTTP1Server
  protocol witness table for NIOHTTP1Server.HTTPHandler : NIO.ChannelHandler in NIOHTTP1Server
  protocol witness table for NIOHTTP1Server.HTTPHandler : NIO.ChannelHandler in NIOHTTP1Server

Any idea what I'm doing wrong?
Thanks,

Ok, issue is fixed. I carelessly imported types declared in main.swift under HTTP1Server target in my prototype code. I created a new source file under Playground and copied the necessary types and now Playground is able to run my code.

1 Like