An initial value for the state object.
Initializerinit(wrapped
init(wrappedValue:)
Creates a new state object with an initial wrapped value.
Availability 有効性
- iOS 14.0+
- iPadOS 14.0+
- macOS 11.0+
- Mac Catalyst 14.0+
- tvOS 14.0+
- watchOS 7.0+
Technology
- Swift
UI
Declaration 宣言
init(wrappedValue thunk: @autoclosure @escaping () -> ObjectType )
Parameters パラメータ
thunk
Discussion 議論
You don’t call this initializer directly.
あなたは、このイニシャライザを直接に呼び出しません。
Instead, declare a property with the @State
attribute in a View
, App
, or Scene
, and provide an initial value:
struct MyView: View {
var model = DataModel()
// ...
}
SwiftUI creates only one instance of the state object for each container instance that you declare. In the code above, SwiftUI creates model
only the first time it initializes a particular instance of My
. On the other hand, each different instance of My
receives a distinct copy of the data model.