1

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?

3

1 Answer 1

1

Try this:

 override func viewDidLoad() {
     var obj = one()
     obj.x++;
     obj.y++;
     obj.z++;
 }
Sign up to request clarification or add additional context in comments.

1 Comment

Unfortunately this returns the exception "expected declaration"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.