I have researched the other questions related to UIStepper and it seems none answer my specific question (and they're all in Objective C).
Here's my code:
class EditItemViewController: UIViewController {
@IBOutlet weak var myTextField: UITextField!
@IBOutlet weak var myStepper: UIStepper!
@IBAction func stepperChanged(sender: UIStepper) {
var currentValue = myTextField()!
let valueFromStepper = Int(sender.value).description
currentValue += valueFromStepper.toInt()!
myTextField = currentValue.description
}
override func viewDidLoad() {
super.viewDidLoad()
myTextField = NSUserDefaults.standardUserDefaults().stringForKey("item")
myStepper.autorepeat = false
}
The text field is populated with a value from UserDefaults. The user can change it in the text field or use the stepper. Right now, clicking the + on the stepper properly adds 1 to the text field value. However, pressing again adds 2, then 3, etc. The decrement feature does not work. What am I missing?