Apple's boilerplate code for UISceneDelegate contains a stub implementation for scene(_:willConnectTo:options:). This starts with:
guard let _ = (scene as? UIWindowScene) else { return }
Is is really possible that we end up in the else branch here? The constructor of UIScene mentions
Subclasses call this method to initialize the scene details.
so my guess is that UIScene should be treated as an abstract base class that is never created directly, only from derived classes. But I didn't find any other classes derived from UIScene. If that holds true, wouldn't it make much more sense to write a forced downcast here?
scene as! UIWindowScene
Or is there a use case where it makes sense to create a user-defined subclass? If so, what would be an example for that and how would it be used?
CarPlay framework has its own
UIScene,UISceneDelegate.UIScene:CPTemplateApplicationDashboardScene,CPTemplateApplicationScene,CPTemplateApplicationInstrumentClusterSceneUISceneDelegate:CPTemplateApplicationSceneDelegate,CPTemplateApplicationDashboardSceneDelegate,CPTemplateApplicationInstrumentClusterSceneDelegateIs force casting is safe? Force casting is safe unless you share SceneDelegate with different
Role.UIKit expects to have concrete subclass of
UIScenefor eachRole. For example,windowExternalDisplayNonInteractive,windowApplication,windowExternalDisplayshould connect toUIWindowScene.Is there a use case where it makes sense to create a user-defined subclass?
Rarely there could be, but using different
UISceneDelegatefor differentRoleis more preferred way.