Using the command line, unable to compile and run a playground with multiple sources.

I have a playground with multiple sources in a Sources directory in addition to the main Contents.swift. I have been unable to compile & run the playground from the command line.

The compiler is unable to resolve any items located in the separate sources and gives multiple error such as

contents.swift:8:26: error: cannot find 'JSON' in scope
print("JSON rawdata\n\n\(JSON)\n")
                         ^~~~

The playground executes successfully from the IDE so the constants & functions etc are declared correctly as Public

I have tried swiftc Contents.swift Sources/JSON.swift Sources/Filemanager.swift etc but with no success

Where am I going wrong?

Replies

I’m having troubles understanding your post. It’d help if you explained it as if I know nothing about your current project, because I don’t! (-:

It seems that you have a Swift playground and you’re trying to build its source code on the Mac from the comand line. Is that right?

If so, that should be feasible, but there are a bunch of potential complexities. I recommend that you create a minimal test playground that reproduces the problem, making note of the steps you took along the way, and then post those steps here so that we can see exactly what you’re doing.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"