Search code examples
iosobjective-cwindowsceneuiscene

What is the difference between a scene and a window in iOS app development?


According to Apple's official documentation:

A scene is represented by a UIScene object. Apple defines this as:

"An object that represents one instance of your app’s user interface"
source: https://developer.apple.com/documentation/uikit/uiscene

A window is represented by a UIWindow object. Apple defines this as:

"The backdrop for your app’s user interface and the object that dispatches events to your views."
source: https://developer.apple.com/documentation/uikit/uiwindow

So then in this image, is this best represented as one scene containing two windows or two separate scenes?

image source: https://developer.apple.com/documentation/uikit/app_and_environment/scenes

To my understanding, this is the high-level structure of an iOS application:
UIApplication -> UIScene -> UIWindow -> UIView

What is the purpose of being able to have both multiple scenes per application and multiple windows per scene? And the differences / distinct usages of the two. Thanks.

The Apple documentation is thorough, but I find its definitions and usages of technical terms to be inconsistent. It also doesn't help that there is no clear example code, especially for Objective-C. The Apple documentation archives have a lot of Objective-C introductory material to learn the language, but not actual iOS development using UIKit.

I also haven't been able to find a definitive answer from the web either. Any insight is appreciated.


Solution

  • The image you reference in the documentation is two scenes. On an iPad, when using split screen multitasking, you are creating additional scenes.

    Think of the old, pre-scene, iOS app structure as always having just a single scene. Now, apps can have multiple scenes to support iPad multitasking. Or if you use Mac Catalyst, your app can have multiple scenes when running on a Mac.

    Whether your app currently has one scene or several, each scene may have one or more windows (though it's most common to have just one). The windows of a scene will be one on top of the other and will fill the full frame of its associated scene.

    In short, use scenes to support multitasking on the iPad. Just stick to one window per scene to host the scene's root view controller and any further view controllers you display. Don't worry about adding additional windows to a scene unless you come across a clear reason to do so.