I’ve a dynamic coloration (let myColor = UIColor.label
) which is designed to seem in another way in gentle and darkish modes.
After I programmatically set darkish theme, after which inquire a coloration’s cgColor
parts, it experiences [1.0, 1.0]. It’s right, as a result of in darkish mode textual content coloration is predicted to be white.
Nevertheless, once I test it from inside dispatch queue, it experiences [0.0, 1.0], as if in gentle theme.
It is a minimal reproducing pattern:
class ViewController: UIViewController {
let myColor: UIColor = .label
override func viewDidLoad() {
tremendous.viewDidLoad()
UIApplication.shared.home windows.forEach {
$0.overrideUserInterfaceStyle = .darkish
}
if let coloration = myColor.cgColor.parts {
print("initially (coloration)")
DispatchQueue.major.async {
if let coloration = self.myColor.cgColor.parts {
print("in queue (coloration)")
}
}
}
}
}
Output:
initially [1.0, 1.0]
in queue [0.0, 1.0]
Any ideas why it occurs and methods to repair it?