Generally I can do as following steps to experiment a swift package in a macOS Playground:
clone the project
use 'swift package generate-xcodeproj' to generate a Xcode project
go to "File -> Save As Workspace..." generate a Xcode workspace
add a macOS Playground into the workspace
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?
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.
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 .
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.
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
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.