Backwards compatibility with buttons in Xcode 13

I have a number of apps which use a custom tab-bar for navigation. The tab-bar uses buttons with an ICON on top and text below. I have this working in Xcode 12.5 with an extension similar to those below. I wanted to see if I could convert to Xcode 13 and take advantage of the new button configurations. I was having some problems getting this to work properly so I did the following testing.

I created a new empty project in Xcode 12.5.1. Closed and re-opened the app in Xcode 13 and added two plain buttons. I didn’t change any of the attributes in the IB so they just have a blue button text. Then I attached one of the extensions below to each button. When the app opens in iSO 15 the buttons display the correct style. However, when either of the buttons is tapped the display reverts back to the text attributes of the button in the IB. So it’s blue, the text reads button and the text size changes back to the default. The ICON and the positioning remain unchanged. 

If I create a new Xcode 13 project and do the exact same thing then everything working fine. Is anybody else seeing this? Is there something I need to change something in the extensions to make it work in pre 13 Xcode?

@available(iOS 15.0, *)
extension UIButton
{
    func settings_MenuBtn()
    {
        self.configuration = .plain()
        let imageConfig = UIImage.SymbolConfiguration(scale: .large)
        self.configuration?.title = "Settings"
        self.configuration?.attributedTitle?.foregroundColor = .white
        self.configuration?.imagePlacement = .top
        self.configuration?.titleAlignment = .center
        self.configuration?.imagePadding = 6
        self.configuration?.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)
        self.configuration?.image = UIImage(systemName: "gearshape", withConfiguration: imageConfig)
        
        self.configuration?.attributedTitle?.font = .systemFont(ofSize: gMenuTextSize, weight: .regular)

    }
}

@available(iOS 15.0, *)
extension UIButton.Configuration
{
    static func settings_MenuBtn2() -> UIButton.Configuration
    {
        let imageConfig = UIImage.SymbolConfiguration(scale: .large)
        var config: UIButton.Configuration = .plain()
        config.title = "Settings"
        config.attributedTitle?.foregroundColor = .white
        config.attributedTitle?.font = .systemFont(ofSize: gMenuTextSize, weight: .regular)

        config.image = UIImage(systemName: "gearshape", withConfiguration: imageConfig)
        config.imagePlacement = .top
        config.titleAlignment = .center
        config.imagePadding = 6
        config.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)

        return config
    }
}

Please how the present extensions you have in the 12.5 project.

When you open the existing project, do you get warnings (in Issues Navigator on the left pane) advising to update to new settings ?

If so, do it.

You could also do a Clean Build Folder.

Finally, search everywhere in code for the button.

I apologize. The title of my question should be:

Forward compatibility problem with buttons when updating app to Xcode 13

As part of the updateConfiguration pass on UIButton, it will apply titles, images, and symbol configuration set via the older API to the configuration in order to make it easier for clients to migrate to configurations. In the case of backwards compatibility, my recommendation would be to use the updateConfigurationHandler to provide a configuration to the button instead of setting the .configuration property directly – this will allow your configuration setup to always take precedent without mixing with content set elsewhere on the UIButton.

Backwards compatibility with buttons in Xcode 13
 
 
Q