'windows' was deprecated in iOS 15.0

 How can I fix this please im getting this error 'windows' was deprecated in iOS 15.0

class func topViewController(controller: UIViewController? = UIApplication.shared.windows.first?.rootViewController) -> UIViewController? {

        if let navigationController = controller as? UINavigationController {

            return topViewController(controller: navigationController.visibleViewController)

        }

        if let tabController = controller as? UITabBarController {

            if let selected = tabController.selectedViewController {

                return topViewController(controller: selected)

            }

        }

        if let presented = controller?.presentedViewController {

            return topViewController(controller: presented)

        }

        return controller

    }

}

Get the window through Scene:

        let windowScene = scenes.first as? UIWindowScene

        let window = windowScene?.windows.first 

An application can use more than one scene, each with one or more windows. Use the connectedScenes method to obtain the list of connected scenes for the application. Use the window or keyWindow property on a scene to obtain the window. If you are certain that your app uses only one scene with one window you could obtain the same root view controller using the following:

guard let firstScene = UIApplication.shared.connectedScenes.first as? UIWindowScene else {
    return
}

guard let firstWindow = firstScene.windows.first else {
    return
}

let viewController = firstWindow.rootViewController
'windows' was deprecated in iOS 15.0
 
 
Q