-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewController.swift
67 lines (48 loc) · 1.46 KB
/
ViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// ViewController.swift
// Calculator
//
// Created by Richard Poutier on 8/29/17.
// Copyright © 2017 Richard Poutier. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var display : UILabel!
private var userIsTyping = false
private var decimalEntered = false
var blo : String = ""
@IBAction func digitPressed(_ sender: UIButton) {
let digit = sender.currentTitle!
let displayString = display.text!
if displayString.contains(".") && digit == "." {
// do this
} else {
if userIsTyping {
let currentDisplayText = display.text!
display.text = currentDisplayText + digit
} else {
display.text = digit
userIsTyping = true
}
}
}
private var brain = CalculatorBrain()
var displayValue : Double {
get {
return Double(display.text!)!
}
set {
display.text! = String(newValue)
}
}
@IBAction func operationPressed(_ sender: UIButton) {
if userIsTyping {
brain.setOperand(displayValue)
userIsTyping = false
}
brain.performOperation(sender.currentTitle!)
if let result = brain.result {
displayValue = result
}
}
}