0

I have a start screen with a log in button and a register button. Both lead to the same view controller, but its interface is based on a variable.

How can I make my startviewcontroller change this var, that can currently only be accessed from the mainviewcontroller?

2 Answers 2

1

I'm temped to say "just like you get access to any other classes properties. However, given you haven't shared any code it's may not be as simple. But in general you will need to have a pointer to an instance or shared instance (singleton) of your mainViewController. And of course those variables need to be public.

Sign up to request clarification or add additional context in comments.

1 Comment

The variables could be internal as well, so I would say they shouldn't be private.
0

You would have to declare that variable global outside any class just below the import statements. You will be able to use the variable anywhere in your code.

import UIKit

var myGlobalVariable: Int

Comments

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.