Gardening some examples (#64)

* Gardening some examples

* Revert variable names
This commit is contained in:
유재호 2023-01-19 03:47:31 +09:00 committed by GitHub
parent f3ccc0b3a1
commit 45a77a21ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 10 deletions

View File

@ -14,7 +14,7 @@ object and synchronizing it to view state with the `bind` view modifier that shi
library. library.
For example, suppose you have a sign in flow where if the API request to sign in fails, you want For example, suppose you have a sign in flow where if the API request to sign in fails, you want
to refocus the email field. The model can be implement like so: to refocus the email field. The model can be implemented like so:
```swift ```swift
class SignInModel: ObservableObject { class SignInModel: ObservableObject {

View File

@ -36,7 +36,7 @@ struct EditView: View {
} }
} }
} else: { } else: {
Text("\(self.string)") Text(self.string)
Button("Edit") { Button("Edit") {
self.editableString = self.string self.editableString = self.string
} }
@ -47,7 +47,7 @@ struct EditView: View {
} }
``` ```
This is the most optimal way to model this domain. Without the ability to deriving a This is the most optimal way to model this domain. Without the ability to derive a
`Binding<String>` from a `Binding<String?>` we would have had to hold onto extra state to represent `Binding<String>` from a `Binding<String?>` we would have had to hold onto extra state to represent
whether or not we are in editing mode: whether or not we are in editing mode:
@ -94,15 +94,15 @@ struct EditView: View {
TextField("Edit string", text: $string) TextField("Edit string", text: $string)
HStack { HStack {
Button("Cancel") { Button("Cancel") {
self.editableString = nil self.editableString = .inactive
} }
Button("Save") { Button("Save") {
self.string = string self.string = string
self.editableString = nil self.editableString = .inactive
} }
} }
} else: { } else: {
Text("\(self.string)") Text(self.string)
Button("Edit") { Button("Edit") {
self.editableString = .active(self.string) self.editableString = .active(self.string)
} }
@ -136,7 +136,7 @@ enum ItemStatus {
case outOfStock(isOnBackOrder: Bool) case outOfStock(isOnBackOrder: Bool)
} }
struct InventoryItemView { struct InventoryItemView: View {
@State var status: ItemStatus @State var status: ItemStatus
var body: some View { var body: some View {

View File

@ -15,7 +15,7 @@ import SwiftUI
/// case outOfStock(isOnBackOrder: Bool) /// case outOfStock(isOnBackOrder: Bool)
/// } /// }
/// ///
/// struct InventoryItemView { /// struct InventoryItemView: View {
/// @State var status: ItemStatus /// @State var status: ItemStatus
/// ///
/// var body: some View { /// var body: some View {

View File

@ -11,7 +11,7 @@ import SwiftUI
/// optional binding. /// optional binding.
/// ///
/// ```swift /// ```swift
/// struct InventoryItemView { /// struct InventoryItemView: View {
/// @State var quantity: Int? /// @State var quantity: Int?
/// ///
/// var body: some View { /// var body: some View {

View File

@ -15,7 +15,7 @@ import SwiftUI
/// case outOfStock(isOnBackOrder: Bool) /// case outOfStock(isOnBackOrder: Bool)
/// } /// }
/// ///
/// struct InventoryItemView { /// struct InventoryItemView: View {
/// @State var status: ItemStatus /// @State var status: ItemStatus
/// ///
/// var body: some View { /// var body: some View {