-3

I am currently building an application with Swift 3 and have defined a color in one ViewController with an let ... = ... statement and want to use this color in another ViewController too without defining it new. Any ideas?

0

2 Answers 2

0

The simplest solution is to define that variable outside of class, for example

import UIkit

let color = UIColor.red

class ScanViewController: UIViewController  {
....
}
Sign up to request clarification or add additional context in comments.

Comments

0

also you could override the init function of the another ViewController, just like:

override init(withColor color: UIColor){
    super.init(nibName: nil, bundle: nil);
}

then you could pass the color as the param:

let viewController = ViewController(withColor: UIColor.red);

but I think the best way is define it globally.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.