2

Here's my code.

My need is if the price label have had number

When pressing add from stepper

I need stepper value to multiply my price number

but I encounter this situation

The price label won't multiply my original number

like if price number originally is 50

I would like to show 50,100,150,200,250

not like this 50 ,100 ,300,400

@IBOutlet weak var stepperValue: UILabel!
@IBOutlet weak var price: UILabel!

@IBAction func stepper(_ sender: UIStepper) {

    let count = Int(sender.value)
    stepperValue.text = String(count)
    let price = Int(price.text!)!
    price.text? = String(price * count)
}

Is there proper way to solve my logical problem?

1 Answers1

2

You need to store original value somewhere and use it for incrementation.

E.g.

@IBOutlet weak var stepperValue: UILabel!
@IBOutlet weak var price: UILabel!

private var originalPrice: Int = 50 // or whatever you want

@IBAction func stepper(_ sender: UIStepper) {

    let count = Int(sender.value)
    stepperValue.text = String(count)

    price.text = String(originalPrice * count)
}
Yevgeniy Leychenko
  • 1,287
  • 11
  • 25