-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProductForm.swift
47 lines (36 loc) · 1.4 KB
/
ProductForm.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import SwiftUI
import Northwind
/**
* A SwiftUI Form to edit the product columns.
*/
struct ProductForm: View {
@Binding var product : Product
var body: some View {
Section("Product Information") {
TextField("Product Name", text: $product.productName)
.help("The name of the product, choose wisely.")
TextField("Price per Unit", value: $product.unitPrice,
format: .currency(code: "USD"))
.help("The price of a single unit, in USD.")
TextField("Quantity per Unit", value: $product.quantityPerUnit,
formatter: .emptyIsNull)
.help("Describe the contents of a unit, e.g. '10 boxes x 20 bags'.")
}
Section("Stock") {
TextField("Units in Stock", value: $product.unitsInStock,
format: .number)
.help("The number of units we have in stock.")
TextField("Units on Order", value: $product.unitsOnOrder,
format: .number)
.help("The number of units we have ordered.")
TextField("Reorder Level", value: $product.reorderLevel,
format: .number)
// Northwind just uses a string for this, should be made a BOOL
// column in the database.
Toggle("Discontinued", isOn: Binding(
get: { product.discontinued != "0" },
set: { product.discontinued = $0 ? "1" : "0" }
))
}
}
}