I just created a class and gave it some vars. Unfortunately I can\'t access these variables in my iOS-Projects
. However, the same syntax works in playground...<
The last two lines need to be inside a function. You can have only declarations in class scope, not expressions to be executed.
The syntax for a class declaration is:
class <class name>: <superclass>, <adopted protocols> {
<declarations>
}
Your declaration of ViewController
includes rex.age = 2
which itself is not a declaration, it is a statement - specifically a binary expression with an infix operator.