UIAppearance Swift 4

After upgrading to Swift 4, I get a compiler error:

Static member 'appearance' cannot be used on protocol metatype 'UIAppearance.Protocol'

Here is my viewWillAppear method in my subclass of Control Bar Controller, I set the font of the element text.

 override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) // compiler error on line below UIAppearance.appearance().setTitleTextAttributes([NSAttributedStringKey.font: font], for: UIControlState.normal) } 

I am having trouble with this, any guidance would be appreciated, thanks!

+7
ios swift swift4 xcode9-beta uiappearance
source share
1 answer

Right - the current Swift 4 conversion tool (starting with Xcode 9 Beta 4) is a little carried away.

I was able to quickly fix the problem by returning the UIAppearance conversion UIAppearance , and then updating the individual attributes.

For example, in Swift 3, I had:

 UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.white], for: .selected) 

Xcode "helped" me by changing it to:

 UIAppearance.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.white], for: .selected) 

I was able to extinguish the errors in half time so that:

 UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.white], for: .selected) 
+8
source share

All Articles