Hello! I started learning swift and on the start I have a problem 😟
print("Hello, World!")
Error: Expected declaration
Can someone help?
In programming languages, the same line -- exactly the same sequence of characters can have different meanings according to the context.
So, if you get an error message at a specific line, you need to show some more context including the line to get a clue to fix it.
For example, this code snippet generates the same error message as you reported:
class MyClass {
print("Hello, World!") //->Expected declaration
}
But this does not:
class MyClass {
func someMethod() {
print("Hello, World!")
}
}