diff --git a/Calculator/Controller/ViewController.swift b/Calculator/Controller/ViewController.swift index f0ce747..288eeed 100644 --- a/Calculator/Controller/ViewController.swift +++ b/Calculator/Controller/ViewController.swift @@ -22,7 +22,11 @@ class ViewController: UIViewController { return number } set { - displayLabel.text = String(newValue) + if floor(newValue) == newValue { + displayLabel.text = String(Int(newValue)) + } else { + displayLabel.text = String(newValue) + } } } @@ -38,9 +42,10 @@ class ViewController: UIViewController { if let calcMethod = sender.currentTitle { - if let result = calculator.calculate(symbol: calcMethod) { - displayValue = result + guard let result = calculator.calculate(symbol: calcMethod) else { + fatalError("Problem with unwrapping value") } + displayValue = result } } diff --git a/Calculator/Model/CalculatorLogic.swift b/Calculator/Model/CalculatorLogic.swift index f1b7c7f..5797486 100644 --- a/Calculator/Model/CalculatorLogic.swift +++ b/Calculator/Model/CalculatorLogic.swift @@ -32,12 +32,13 @@ struct CalculatorLogic { return performTwoNumCalculation(n2: n) default: intermediateCalculation = (n1: n, calcMethod: symbol) + return n } } return nil } - private func performTwoNumCalculation(n2: Double) -> Double? { + private func performTwoNumCalculation(n2: Double) -> Double { if let n1 = intermediateCalculation?.n1, let operation = intermediateCalculation?.calcMethod { @@ -55,7 +56,7 @@ struct CalculatorLogic { fatalError("The operation passed in does not match any of the cases.") } } - return nil + return n2 } }