Issue with SceneStorage in ViewModifer, but not in View

Hello, Awhile ago I'd refactored my code to have @SceneStorage in a ViewModifier and not on a View. In Xcode 15.3, I see a runtime-only warning:

SceneStorage is only for use with SwiftUI App Lifecycle. This will become a fatal error in a future release.
Accessing a SceneStorage value outside of being installed on a View. This will always return the default value.
Creating a Binding to SceneStorage value outside of being installed on a View. This will result in a constant Binding of the default value and will not update.

I'd used a ViewModifier to encapsulate this code. Why is that different than a View?

If you are interested you can see an example here: https://github.com/bolsinga/site/blob/ffbedd7fb134675496f529cf62484ceb9b79d360/Sources/Site/Music/UI/ArchiveStorageModifier.swift#L15

Thanks for any tips!

Answered by Bolsinga in 801871022

With the same code, the warning is gone in Xcode 15.4, where I target x.5 releases of iOS and macOS.

Just as the message states, it is to be only used within a SwiftUI View where the context of a scene exists.

I'm sorry; I see the message. I do not understand why the ViewModifier (which knows the View) is different in this manner than the View itself. Thanks.

Accepted Answer

With the same code, the warning is gone in Xcode 15.4, where I target x.5 releases of iOS and macOS.

Issue with SceneStorage in ViewModifer, but not in View
 
 
Q