Reputation: 51
For the life of me I cannot find the solution anywhere, so it seems to me it is a Xcode playground bug.
Within the Sources folder, despite me declaring a class as public, when I try to access the class from a separate file (within the Sources folder), compiler will give me an error message that says it cannot find the class in scope.
However, when I run the playground and ignore the message, the program will build and run successfully, and the error message will disappear until I start to modify the code.
Strangely enough, it doesn't happen at in an App project; it only happens in playground.
I've made a simple demonstration using a playground file called "test" and screenshoted what has happened, which you can see in the attached photo below, please advise! Thanks a lot!
Tried solutions include:
Cannot find Person class in scope despite it being marked public
But the Person class is marked as public
Code compiles successfully regardless
Error disappear after running the playground, but comes right back as soon as I modify it
Upvotes: 5
Views: 528
Reputation: 535138
Strangely enough, it doesn't happen at in an App project; it only happens in playground.
Actually that part is exactly what is not strange. App projects are predictable. Playgrounds are the work of the devil and it's easy to make them behave incorrectly.
What you're seeing is certainly a bug, especially because it can't readily be reproduced by others. On my machine, there are no error messages and everything runs fine:
You might try adding import test_Sources
to the troublesome file, but I can't guarantee it will make a difference. What I really recommend is that you avoid playgrounds.
Upvotes: 1