Not able to reference classes/structs in Swift playground sources

I have to admit that this is strange for me. Though I have been using playgrounds for years, but I only write small pieces of code to test simple ideas, and I never used another source file.

Today I want to add a new struct in Sources folder. To my surprise, I am not able to reference the struct in the main playground file.

Sources/testlets.swift:

struct Dummy {
    var name: String
}

MyPlayground:

var box = Dummy(name: "abc")
// error: /.../MyPlayground.playground:22:11 Cannot find 'Dummy' in scope
Accepted Answer

You have to mark your struct Dummy and var name as public.

Playgrounds puts all files in the sources folder in its own bundle module

Correct.

Share and Enjoy

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

Not able to reference classes/structs in Swift playground sources
 
 
Q