diff --git a/Ratios/CalculatorViewController.swift b/Ratios/CalculatorViewController.swift index a7b42a5..1368cca 100644 --- a/Ratios/CalculatorViewController.swift +++ b/Ratios/CalculatorViewController.swift @@ -148,7 +148,7 @@ class CalculatorViewController: UIViewController { self.stackViewWidthConstraint?.isActive = true } - func updateBackgroundColor(_ ratio: Int, duration: TimeInterval = 0.15) { + func updateBackgroundColor(_ ratio: Double, duration: TimeInterval = 0.15) { UIView.animate(withDuration: duration, delay: 0, options: [.curveEaseInOut, .allowUserInteraction], animations: { let newBackgroundColor = BrewStrengthColor.colorFor(ratio) self.view.backgroundColor = newBackgroundColor @@ -157,7 +157,7 @@ class CalculatorViewController: UIViewController { } @objc func handleFieldValueChange(_ sender: AnyObject) { - let ratio = Int(self.ratioInputView.textField.text ?? "16") ?? 16 + let ratio = Double(self.ratioInputView.textField.text ?? "16") ?? 16 var total = Double(self.totalInputView.textField.text ?? "0") ?? 0 var water = Double(self.waterInputView.textField.text ?? "0") ?? 0 var grounds = Double(self.groundsInputView.textField.text ?? "0") ?? 0 diff --git a/Ratios/Helpers/Calculator.swift b/Ratios/Helpers/Calculator.swift index fbdbd51..0ff137d 100644 --- a/Ratios/Helpers/Calculator.swift +++ b/Ratios/Helpers/Calculator.swift @@ -10,21 +10,21 @@ import Foundation struct Calculator { - static func calculateGrounds(brew: Double, ratio: Int) -> Double { + static func calculateGrounds(brew: Double, ratio: Double) -> Double { guard ratio > 2 else { return 0 } return brew / Double(ratio - 2) } - static func calculateGrounds(water: Double, ratio: Int) -> Double { + static func calculateGrounds(water: Double, ratio: Double) -> Double { guard ratio > 0 else { return 0 } return water / Double(ratio) } - static func calculateWater(grounds: Double, ratio: Int) -> Double { + static func calculateWater(grounds: Double, ratio: Double) -> Double { return grounds * Double(ratio) } diff --git a/Ratios/Helpers/PersistenceStore.swift b/Ratios/Helpers/PersistenceStore.swift index e8e5a33..1de4786 100644 --- a/Ratios/Helpers/PersistenceStore.swift +++ b/Ratios/Helpers/PersistenceStore.swift @@ -9,8 +9,8 @@ import Foundation protocol PersistenceStore { - func save(grounds: Double, ratio: Int) - func getValues() -> (grounds: Double, ratio: Int) + func save(grounds: Double, ratio: Double) + func getValues() -> (grounds: Double, ratio: Double) } extension UserDefaults: PersistenceStore { @@ -18,14 +18,14 @@ extension UserDefaults: PersistenceStore { private static let ratiosPersistenceGroundsKey = "co.brushedtype.ratios.grounds" private static let ratiosPersistenceRatioKey = "co.brushedtype.ratios.ratio" - func save(grounds: Double, ratio: Int) { + func save(grounds: Double, ratio: Double) { self.set(grounds, forKey: UserDefaults.ratiosPersistenceGroundsKey) self.set(ratio, forKey: UserDefaults.ratiosPersistenceRatioKey) } - func getValues() -> (grounds: Double, ratio: Int) { + func getValues() -> (grounds: Double, ratio: Double) { let grounds = self.double(forKey: UserDefaults.ratiosPersistenceGroundsKey) - let ratio = self.integer(forKey: UserDefaults.ratiosPersistenceRatioKey) + let ratio = self.double(forKey: UserDefaults.ratiosPersistenceRatioKey) let groundsOrFallback = grounds > 0 ? grounds : 12 let ratioOrFallback = ratio > 0 ? ratio : 16