Initialize class-instance and access variables in Swift

swift

Solution

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.

Problem

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... ``` class ViewController: UIViewController { class Dog { var age = 0 var hungry = TRUE } var rex = Dog() rex.age = 2 //ERROR: EXPECTED DECLARATION } ```

Original source