'How to store an enum with an associated value in @SceneStorage
I'm new to SwiftUI and Swift development, although I have lots of other development experience. I am trying to store the value of an enumeration in Swift(UI) using the @SceneStorage property wrapper.
It is my first macOS app, and I would like to do this because the sidebar of the app I am tinkering around with represents documents that may be grouped in Core Data by some group ID (like a folder ID), or they may be pseudo- or meta-groups of documents, such as "All" or "Recent". I would like my app to remember which document group is selected.
The enum looks like this:
enum DocumentGrouping {
case all
case recent
case folder(UUID)
}
...and my @SceneStorage declaration looks like this:
@SceneStorage("selection") private var selectedDocumentGrouping: DocumentGrouping
However, Swift(UI) complains "No exact matches in call to initializer." How do I get around this?
Or, if this is not a good approach, how can I rework my sidebar's List(selection: $selectedDocumentGrouping) to best implement this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
