Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISegmentedControl error after upgrading to Xcode 11.x

After installing Xcode 11, when testing on iOS 12 mobile device, the following error keeps appearing. It always crashes the application.

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UISegmentedControl 0x107c7ec90> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key selectedSegmentTintColor.'

On iOS 13, it does not crash.

like image 208
Seop Yoon Avatar asked Mar 03 '23 07:03

Seop Yoon


1 Answers

This error was caused from setting Selected Tint color from xib file. When it is set to a predefined color (in Colors.xcassets), it would cause the above error on runtime and crash the app.

enter image description here

To handle tint color that would work, it has to be done programmatically.

if #available(iOS 13.0, *) {
    unitSegment.selectedSegmentTintColor = UIColor(named: "Primary")!
} else {
    unitSegment.tintColor = UIColor(named: "Primary")!
}

As of now, the crashing error appears on both Xcode 11.0 and Xcode 11.1.
Apple should have handled this by default on Xcode and Swift 5.1, or at least prompted an error upon choosing a predefined color on xib file especially when my target is set to 12.0.

like image 71
Seop Yoon Avatar answered Mar 23 '23 03:03

Seop Yoon