Swift key paths compile error in Xcode 12.1 (12A7403)

Hi,

I've tried upgrading my project from Xcode 11.7 (11E801a) to Xcode 12 through 12.1 (12A7403) and I keep hitting a compile error with this code:
Code Block swift
let navigationBarControllerState: [PartialKeyPath<UINavigationController>: Any] = [\UINavigationController.isNavigationBarHidden: false,
\UINavigationController.navigationBar.barStyle: UIBarStyle.black,
\UINavigationController.navigationBar.isTranslucent: true,
\UINavigationController.navigationBar.tintColor: UIColor.white,
\UINavigationController.hidesBarsOnTap: true]


Here's the error:

Sources/Controllers/CompareViewController.swift:285:96: error: value of type 'UIViewController' has no member 'navigationBar'                                                                                           \UINavigationController.navigationBar.tintColor: UIColor.white,

The same code compiles correctly in Xcode 11 and I've tried it in the Playgrounds app where it also compiles without error.

I've made no other changes to the project.

Any help appreciated.

The same error occurs in Xcode 12.0.1. And I cannot find why Swift compiler does not like tintColor.

In my opinion, this is a bug of Swift compiler and you should better send a feedback.


A possible workaround. (Only tested in 12.0.1.)
Declare the key somewhere else.
Code Block
static let tintColorKey: PartialKeyPath<UINavigationController> = \UINavigationController.navigationBar.tintColor
let navigationBarControllerState: [PartialKeyPath<UINavigationController>: Any] = [
\UINavigationController.isNavigationBarHidden: false,
\UINavigationController.navigationBar.barStyle: UIBarStyle.black,
\UINavigationController.navigationBar.isTranslucent: true,
tintColorKey: UIColor.white,
\UINavigationController.hidesBarsOnTap: true
]

(static may not be needed depending on where you declare navigationBarControllerState.
Thanks for confirming OOPer and the workaround. I've also been able to change the variable to a var and do this:
Code Block swift
navigationBarControllerState[\UINavigationController.navigationBar.tintColor] = UIColor.white


I submitted this as a bug in the Feedback Assistant too.
Swift key paths compile error in Xcode 12.1 (12A7403)
 
 
Q