Not able to use UITabBarControllerDelegate.tabBarController(:didSelectTab:previousTab:)

In iOS18, Not able to use the UITabBarControllerDelegate.tabBarController(:didSelectTab:previousTab:) function. Since it have duplicate parameter name for didselectTab and previousTab , we're getting Invalid redeclaration of 'tab' error.

Answered by Scott in 797348022

You just need to change one or both of those parameter names in your code. The argument labels (didSelectTab and previousTab) are part of the method signature and need to match the protocol declaration, but the parameter names can be whatever you want.

I’d recommend this:

func tabBarController(
    _ tabBarController: UITabBarController,
    didSelectTab selectedTab: UITab, // better parameter name
    previousTab: UITab? // no custom parameter name needed
)

(Or you can omit tabBarController and selectedTab entirely if you don’t actually use them in your code.)

Also consider entering a Feedback to report that the method declaration in the SDK is poorly formed. Presumably your error came after letting Xcode auto-generate the method for you based on its declaration. So it would be better if the SDK declaration were formed like my proposal above.

Accepted Answer

You just need to change one or both of those parameter names in your code. The argument labels (didSelectTab and previousTab) are part of the method signature and need to match the protocol declaration, but the parameter names can be whatever you want.

I’d recommend this:

func tabBarController(
    _ tabBarController: UITabBarController,
    didSelectTab selectedTab: UITab, // better parameter name
    previousTab: UITab? // no custom parameter name needed
)

(Or you can omit tabBarController and selectedTab entirely if you don’t actually use them in your code.)

Also consider entering a Feedback to report that the method declaration in the SDK is poorly formed. Presumably your error came after letting Xcode auto-generate the method for you based on its declaration. So it would be better if the SDK declaration were formed like my proposal above.

Not able to use UITabBarControllerDelegate.tabBarController(:didSelectTab:previousTab:)
 
 
Q