Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save guard let in calcButtonPressed, add functionality to show round … #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Calculator/Controller/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand All @@ -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
}
}

Expand Down
5 changes: 3 additions & 2 deletions Calculator/Model/CalculatorLogic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -55,7 +56,7 @@ struct CalculatorLogic {
fatalError("The operation passed in does not match any of the cases.")
}
}
return nil
return n2
}

}