Marcello B.
Marcello B.

Reputation: 4440

How to update a variable in a class from a nested class swift

I was wondering how I can update variables in a class from within a nested class:

class one {
    var x:Int = 0;
    var y:Int = 0;
    var z:Int = 0;
    var questionFive:Int = 0;

    let totalq = 5;

    internal var totalright = 0;

    class two: UIViewController {

        override func viewDidLoad() {
            x++;
            y++;
            z++;
        }
    }

}

With the code above it will return the error

'one.Type' does not have a member named 'x'

(and the same error code for y and z).

Therefore I was wondering how I can update a variable from a nested class with swift?

Upvotes: 1

Views: 536

Answers (1)

Kiran Thapa
Kiran Thapa

Reputation: 1240

Try this:

 override func viewDidLoad() {
     var obj = one()
     obj.x++;
     obj.y++;
     obj.z++;
 }

Upvotes: 1

Related Questions