Вот код основного vc. Могу выложить проект, там нет ничего секретного, просто отрабатываю некоторые технологии.
import UIKit
import AudioToolbox
import AVFoundation
var clockStep = 1
var useVibration: Bool = true
var useSoundPlay: Bool = true
@IBDesignable
class ViewController: UIViewController {
var counter = 0
var audioPlayer: AVAudioPlayer?
let mySound = URL(fileURLWithPath: Bundle.main.path(forResource: "digi_plink", ofType: "wav")!)
@IBOutlet weak var label: UILabel!
@IBOutlet weak var clockMainScreen: UILabel!
@IBAction func resetButton(_ sender: Any) {
let mySound = URL(fileURLWithPath: Bundle.main.path(forResource: "pop_drip", ofType: "wav")!)
do{
audioPlayer = try AVAudioPlayer(contentsOf: mySound)
audioPlayer!.prepareToPlay()
audioPlayer!.play()
} catch {}
AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
counter = 0
label.text = String (counter)
clockMainScreen.text = String (clockStep)
}
@IBAction func minusButton(_ sender: Any) {
if counter - clockStep > 0 {
counter = counter - clockStep
label.text = String (counter)
} else {
counter = 0
label.text = String (counter)
}
clockMainScreen.text = String (clockStep)
if useVibration {
AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
}
if useSoundPlay {
do{
audioPlayer = try AVAudioPlayer(contentsOf: mySound)
audioPlayer!.prepareToPlay()
audioPlayer!.play()
} catch {}
}
}
@IBAction func plusButton(_ sender: Any) {
if counter + clockStep >= 999 {
counter = 999
} else {
counter = counter + clockStep
label.text = String (counter)
}
clockMainScreen.text = String (clockStep)
if useVibration {
AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
}
if useSoundPlay {
do{
audioPlayer = try AVAudioPlayer(contentsOf: mySound)
audioPlayer!.prepareToPlay()
audioPlayer!.play()
} catch {}
}
}
override func viewDidLoad() {
super.viewDidLoad()
clockMainScreen.text = String (clockStep)
if UserDefaults.standard.value(forKey: "counterStepperValue") != nil {
clockMainScreen?.text = String (clockStep)
} else {
clockMainScreen?.text = String ("1")
}
navigationController?.isNavigationBarHidden = true
self.navigationController?.popViewController(animated: true)
}
func viewWillAppear() {
clockMainScreen.text = String (clockStep)
}
func viewDidAppear() {
clockMainScreen.text = String (clockStep)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}