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?
Tony-Y
(Tony Y)
2
I think you must create a module.modulemap of CNIOAtomics.
lukasa
(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.
@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:
- Create a new Xcode project for macOS
pod init
- edit
Podfile and put
pod 'SwiftNIO'
pod 'SwiftNIOTransportServices'
there
pod install
- close the Xcode project
- open the Xcode workspace created by Cocoapods
- File -> New -> Playgrond, select Blank
- 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
.
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