Overview
概要
You use SceneStorage
when you need automatic state restoration of the value. SceneStorage
works very similar to State
, except its initial value is restored by the system if it was previously saved, and the value is· shared with other SceneStorage
variables in the same scene.
The system manages the saving and restoring of SceneStorage
on your behalf. The underlying data that backs SceneStorage
is not available to you, so you must access it via the SceneStorage
property wrapper. The system makes no guarantees as to when and how often the data will be persisted.
Each Scene
has its own notion of SceneStorage
, so data is not shared between scenes.
Ensure that the data you use with SceneStorage
is lightweight. Data of a large size, such as model data, should not be stored in SceneStorage
, as poor performance may result.
If the Scene
is explicitly destroyed (e.g. the switcher snapshot is destroyed on iPadOS or the window is closed on macOS), the data is also destroyed. Do not use SceneStorage
with sensitive data.