"Cannot find (...) in scope"

Hello! I am a new to programming and developing and I have a question: I tried using Xcode and copied my code from Playgrounds into my Xcode Project. But now it says 50 times "Cannot find (...) in scope." In Playgrounds my code worked. What am I doing wrong? Thank you very much!

Answered by Claude31 in 715334022

You should show the code !

Please give at least an example where the error shows. Maybe you forgot some import ? Or you have a var declared out of scope ?

But hard to say without code.

Accepted Answer

You should show the code !

Please give at least an example where the error shows. Maybe you forgot some import ? Or you have a var declared out of scope ?

But hard to say without code.

Playgrounds and an actual project are different in syntax. Specifically when you're going to a view controller which you are if you're working in contentView. A view uses SwiftUI which is what you see and interact with (an interface) and classes use Swift. The code for these two are not interchangeable which is why you're getting this error. If you have any questions or specific examples of your code that's getting an error just reply to this response.

This is the "Choose your story" learning App on Playgrounds. I removed all code from the new Xcode file and copied this in there. Here is the code! Thank you all!

You'll need to import PlaygroundSupport. Xcode is usually used for writing apps, not playgrounds.

"Cannot find (...) in scope"
 
 
Q