From 4f81fc344539bb7850c028808d002d29bd06e5c8 Mon Sep 17 00:00:00 2001 From: Pin Lin Date: Wed, 6 May 2020 06:12:37 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E4=B8=80=E5=80=8B=E9=99=A3=E5=88=97?= =?UTF-8?q?=E4=BE=86=E5=AD=98=E6=94=BE=E5=BC=8F=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AndroidCalculator/Calculator.swift | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/AndroidCalculator/Calculator.swift b/AndroidCalculator/Calculator.swift index 9656303..41a0982 100644 --- a/AndroidCalculator/Calculator.swift +++ b/AndroidCalculator/Calculator.swift @@ -9,14 +9,26 @@ import Foundation class Calculator { - var process = "" + var formula = ["0"] + + var process: String { + get { + var result = "" + formula.forEach { (item) in + result.append(item) + } + return result + } + } var result = "" func click(_ text: String) { - if text == "AC" { - process = "" - } else { - process += text + switch text { + case "AC": + // 清空到剩下 0 + formula = ["0"] + default: + formula.append(text) } } }