diff --git a/Counter/Base.lproj/Main.storyboard b/Counter/Base.lproj/Main.storyboard index 25a7638..be8d96d 100644 --- a/Counter/Base.lproj/Main.storyboard +++ b/Counter/Base.lproj/Main.storyboard @@ -1,24 +1,149 @@ - + + - + + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Counter/ViewController.swift b/Counter/ViewController.swift index fa1cbf6..ce24fe3 100644 --- a/Counter/ViewController.swift +++ b/Counter/ViewController.swift @@ -7,13 +7,59 @@ import UIKit -class ViewController: UIViewController { +extension UITextView { + func appendString(text: String) { + self.text = text + self.text + } +} + +class ViewController: UIViewController { + @IBOutlet weak var counterLabel: UILabel! + @IBOutlet weak var historyTextView: UITextView! + private var currentData: String { + let formatterDate = DateFormatter() + formatterDate.dateFormat = "[dd.MM.YYYY HH:mm]:" + return formatterDate.string(from: Date()) + } + private var count: Int = 0 { + willSet(newValue) { + counterLabel.text = "Значение счётчика:\n\n\(newValue)" + } + } + override func viewDidLoad() { super.viewDidLoad() - // Do any additional setup after loading the view. } - - + + @IBAction func plusButton() { + //check on max value + guard count != Int.max else { + historyTextView.appendString(text: "\(currentData) попытка увеличить значение счётчика выше максимума\n\n") + return + } + + count += 1 + historyTextView.appendString(text: "\(currentData) значение изменено на +1\n\n") + } + + @IBAction func minusButton() { + //check on min value + guard count != 0 else { + historyTextView.appendString(text: "\(currentData) попытка уменьшить значение счётчика ниже 0\n\n") + return + } + + count -= 1 + historyTextView.appendString(text: "\(currentData) значение изменено на -1\n\n") + } + + @IBAction func resetButton() { + count = 0 + historyTextView.appendString(text: "\(currentData) значение сброшено\n\n") + } + } + +