Initializer

init(wrappedValue:_:store:)

Creates a property that can read and write to a string user default, transforming that to RawRepresentable data type.

Declaration 宣言

init(wrappedValue: Value, _ key: String, store: UserDefaults? = nil) where Value : RawRepresentable, Value.RawValue == String

Parameters パラメータ

wrappedValue

The default value if a string value is not specified for the given key.

key

The key to read and write the value to in the user defaults store. user defaults storeにおいてその値を読み出すそして書き出すためのキー。

store

The user defaults store to read and write to. A value of nil will use the user default store from the environment. それに読み出しおよび書き出しするuser defaults store。nilの値は、その環境からのuser default storeを使います。

Discussion 議論

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

enum MyEnum: String { case a case b case c } struct MyView: View { @AppStorage(“MyEnumValue”) private var value = MyEnum.a var body: some View { … } }

See Also 参照

Storing a Value