Initializer

init(_:)

Creates a property that can save and restore an Optional string, transforming it to an Optional RawRepresentable data type.

Declaration 宣言

init<R>(_ key: String) where Value == Optional<R>, R : RawRepresentable, R.RawValue == String

Parameters パラメータ

key

a key used to save and restore the value.

Discussion 議論

Defaults to nil if there is no restored value

A common usage is with enumerations: 一般的な使用法は、列挙でとなります:


enum MyEnum: String {
    case a
    case b
    case c
}
struct MyView: View {
    @SceneStorage("MyEnumValue") private var value: MyEnum?
    var body: some View { ... }
}

See Also 参照

Storing an Optional Value