用一個陣列來存放式子
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user