Initializer

init(_:)

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

Declaration 宣言

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

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: Int {
    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