Quantity And Total
Part of the Introduction to SwiftUI section of Coddy's Swift journey. Lesson 46 of 50.
Challenge
MediumKeep everything from the previous steps. In OrderView:
- Add a
@Statequantitystarting at1and aSteppertitledQuantity: 1, ... from1to5, with the identifierquantity. - Add a computed property
extra:0for Small,0.5for Medium and1.0for Large. - Show the total,
(price + extra) * quantity, asTotal: $4.25(two decimals) in the.headlinefont, with the identifiertotal, below the stepper.
Try it yourself
import SwiftUI
@main
struct CoddyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}All lessons in Introduction to SwiftUI
Practice on your own: Swift playground