- 履歴一覧
- ソース を表示
- 履歴 を表示
- PropertyWrapper は削除されています。
- 追加された行はこの色です。
- 削除された行はこの色です。
#author("2022-11-15T13:45:21+00:00","default:src128","src128")
&tag(PropertyWrapper);
*目次 [#o1ea3b3a]
#contents
*関連ページ [#jbf0ecac]
*参考情報 [#ca4c6609]
-[[SwiftUIのデータ管理 Property Wrapper編:https://blog.personal-factory.com/2021/01/23/how-to-use-propertywrapper-in-swiftui/]]
#author("2022-11-16T04:34:22+00:00","default:src128","src128")
*Property Wrapperの種類 [#l9739a89]
-@State、@Binding、@StateObject、@ObservedObjectなどデータを管理するためのProperty Wrapperがたくさん存在する
** @State [#b535e418]
-データが値型。データの更新あり。データの発生源がVIewの場合に使用。
-ボタンをタップするとその数字が増える。
#pre{{
struct StateSample: View {
private var counter = 0
var body: some View {
Button(action: {
self.counter += 1
}, label: {
Text("counter is \(counter)")
})
}
}
}}
** @Binding [#pd81fb92]
-データが値型。データの更新あり。データの発生源は外部。
#pre{{
struct ParentView: View {
@State private var counter = 0
var body: some View {
ChildView(counter: $counter)
.frame(width: .infinity)
}
}
struct ChildView: View {
@Binding var counter: Int
var body: some View {
Button(action: {
counter += 1
}, label: {
Text("\(counter)")
.font(.title)
})
.border(Color.red)
}
}
}}