-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?

FelixSFD
  • 6,052
  • 10
  • 43
  • 117

2 Answers2

0

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

import UIkit

let color = UIColor.red

class ScanViewController: UIViewController  {
....
}
Vah.Sah
  • 522
  • 1
  • 6
  • 21
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.

Abel Lee
  • 55
  • 1
  • 10