Skip to content

Commit

Permalink
Completes extra credit 1 and closes #12
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Vanhoef authored and Peter Vanhoef committed Mar 26, 2017
1 parent 62ca500 commit 57a49ca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Calculator/Calculator/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<fontDescription key="fontDescription" type="system" pointSize="30"/>
<state key="normal" title="BS"/>
<connections>
<action selector="clear:" destination="BYZ-38-t0r" eventType="touchUpInside" id="qr1-Ca-0eX"/>
<action selector="backspace:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Klu-Xx-Mpz"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="NCt-oF-aVp">
Expand Down
12 changes: 12 additions & 0 deletions Calculator/Calculator/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,17 @@ class ViewController: UIViewController {
displayValue = 0
sequence.text = " "
}

@IBAction func backspace(_ sender: UIButton) {
if userIsInTheMiddleOfTyping {
var textCurrentlyInDisplay = display.text!
textCurrentlyInDisplay.remove(at: textCurrentlyInDisplay.index(before: textCurrentlyInDisplay.endIndex))
if textCurrentlyInDisplay.isEmpty {
userIsInTheMiddleOfTyping = false
textCurrentlyInDisplay = "0"
}
display.text = textCurrentlyInDisplay
}
}
}

0 comments on commit 57a49ca

Please sign in to comment.